suiss/uim · React Native Component
Combobox
A text input that filters a list of options as you type, for single or multiple selection.
Combobox is an open-source mobile component from suiss/uim for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.


import * as React from "react"
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
function ComboboxDemo({
defaultValue = null,
defaultOpen,
disabled,
showClear,
labelledBy,
invalid,
}: {
defaultValue?: string | null
defaultOpen?: boolean
disabled?: boolean
showClear?: boolean
labelledBy?: string
invalid?: boolean
}) {
const [value, setValue] = React.useState<string | null>(defaultValue)
return (
<Combobox
items={frameworks}
value={value}
onValueChange={setValue}
defaultOpen={defaultOpen}
disabled={disabled}
>
<ComboboxInput
className="w-64"
placeholder="Select a framework"
showClear={showClear}
disabled={disabled}
invalid={invalid}
accessibilityLabelledBy={labelledBy}
/>
<ComboboxContent>
<ComboboxEmpty>No framework found.</ComboboxEmpty>
<ComboboxList>
{(item: string) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
export function ComboboxOpenByDefaultExample() {
return (
<ComboboxDemo defaultValue="Expo" defaultOpen />
)
}import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Combobox
@Composable
fun ComboboxOpenByDefaultExample() {
ComboboxDemo(defaultValue = "Expo")
}
val ComboboxFrameworks = listOf("Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro", "Gatsby", "Expo")
@Composable
fun ComboboxDemo(
defaultValue: String? = null,
disabled: Boolean = false,
showClear: Boolean = false,
label: String? = null,
invalid: Boolean? = null,
) {
var value by rememberSaveable { mutableStateOf(defaultValue) }
Column {
Combobox(
items = ComboboxFrameworks,
value = value,
onValueChange = { value = it },
modifier = Modifier
.width(256.dp)
.then(if (label != null) Modifier.semantics { contentDescription = label } else Modifier),
placeholder = "Select a framework",
emptyText = "No framework found.",
showClear = showClear,
invalid = invalid,
enabled = !disabled,
)
}
}Combobox pairs a text input with a floating list that filters its items as the user types. ComboboxInput draws the field with a caret trigger and an optional clear button, and ComboboxContent renders the list through a portal (inside a full-window overlay on iOS), positioned below the input and as wide as it.
For multiple selection, set multiple and use ComboboxChips with a ComboboxChip per selected value and a ComboboxChipsInput for typing. Each chip has a remove button.
Installation
$ pnpm dlx @esuiss/uim@latest add combobox$ pnpm dlx @esuiss/uim@latest add combobox --platform swift$ pnpm dlx @esuiss/uim@latest add combobox --platform kotlinThe CLI also adds what it builds on: Button, Icon, Text.
Manual
- Install the dependencies:
npx expo install cn phosphor-react-native react-native-reanimated react-native-screens react-native-svg react-native-worklets-
Add the pieces it builds on: Button, Icon, Text, and the primitives
components/primitives/combobox.tsx,components/primitives/field.tsx,components/primitives/positioner.tsx,components/primitives/use-render.tsx. -
Copy the source into
components/ui/combobox.tsx:
import { cn } from "cn"
import { CaretDownIcon, CheckIcon, XIcon } from "phosphor-react-native"
import * as React from "react"
import {
Platform,
type StyleProp,
type View,
type ViewStyle,
} from "react-native"
import { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated"
import { FullWindowOverlay as RNFullWindowOverlay } from "react-native-screens"
import * as ComboboxPrimitive from "@/components/primitives/combobox"
import { useFieldRootContext } from "@/components/primitives/field"
import { useOptionalPositionerContext } from "@/components/primitives/positioner"
import {
resolveClassName,- Update the import paths to match your project.
- Install the dependencies:
npx expo install cn nativewind phosphor-react-native react-native-reanimated react-native-screens react-native-svg react-native-worklets-
Add the pieces it builds on: Button, Icon, Text, and the primitives
components/primitives/combobox.tsx,components/primitives/field.tsx,components/primitives/positioner.tsx,components/primitives/use-render.tsx. -
Copy the source into
components/ui/combobox.tsx:
import { cn } from "cn"
import { cssInterop } from "nativewind"
import { CaretDownIcon, CheckIcon, XIcon } from "phosphor-react-native"
import * as React from "react"
import {
Platform,
type StyleProp,
TextInput,
type View,
type ViewStyle,
} from "react-native"
import { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated"
import { FullWindowOverlay as RNFullWindowOverlay } from "react-native-screens"
import * as ComboboxPrimitive from "@/components/primitives/combobox"
import { useFieldRootContext } from "@/components/primitives/field"
import { useOptionalPositionerContext } from "@/components/primitives/positioner"- Update the import paths to match your project.
- Install the dependencies:
npx expo install phosphor-react-native react-native-reanimated react-native-screens react-native-svg react-native-worklets-
Add the pieces it builds on: Button, Icon, Text, and the primitives
components/primitives/combobox.tsx,components/primitives/field.tsx,components/primitives/positioner.tsx,components/primitives/use-render.tsx. -
Copy the source into
components/ui/combobox.tsx:
import { CaretDownIcon, CheckIcon, XIcon } from "phosphor-react-native"
import * as React from "react"
import {
Platform,
type StyleProp,
StyleSheet,
type TextStyle,
type View,
type ViewStyle,
} from "react-native"
import { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated"
import { FullWindowOverlay as RNFullWindowOverlay } from "react-native-screens"
import * as ComboboxPrimitive from "@/components/primitives/combobox"
import { useFieldRootContext } from "@/components/primitives/field"
import { useOptionalPositionerContext } from "@/components/primitives/positioner"
import { resolveStyle } from "@/components/primitives/use-render"- Update the import paths to match your project.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
.package(url: "https://github.com/phosphor-icons/swift", from: "2.1.0")- Copy the theme files every view uses:
import SwiftUI
import UIKit
struct RGBA: Sendable {
let red: CGFloat
let green: CGFloat
let blue: CGFloat
let alpha: CGFloat
init(_ hex: UInt32, _ alpha: CGFloat = 1) {
red = CGFloat((hex >> 16) & 0xFF) / 255
green = CGFloat((hex >> 8) & 0xFF) / 255
blue = CGFloat(hex & 0xFF) / 255
self.alpha = alpha
}import SwiftUI
extension Color {
public static let surface = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000))
public static let surfaceSecondary = Color.adaptive(light: .init(0xF5F5F7), dark: .init(0x161617))
public static let surfaceTertiary = Color.adaptive(light: .init(0xE8E8ED), dark: .init(0x2C2C2E))
public static let surfaceRaised = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
public static let label = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
public static let labelSecondary = Color.adaptive(light: .init(0x6E6E73), dark: .init(0xA1A1A6))
public static let labelTertiary = Color.adaptive(light: .init(0x86868B), dark: .init(0x86868B))
public static let labelQuaternary = Color.adaptive(light: .init(0xD2D2D7), dark: .init(0x424245))
public static let control = Color.adaptive(light: .init(0x000000, 0.04), dark: .init(0xFFFFFF, 0.1))
public static let controlPressed = Color.adaptive(light: .init(0x000000, 0.12), dark: .init(0xFFFFFF, 0.22))
public static let controlSelected = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
public static let controlDisabled = Color.adaptive(light: .init(0x000000, 0.03), dark: .init(0xFFFFFF, 0.05))
public static let onControlSelected = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000))- Copy the source and every file it uses:
import PhosphorSwift
import SwiftUI
public struct Combobox<Item: Hashable & Sendable>: View {
let items: [Item]
let single: Binding<Item?>?
let multiple: Binding<[Item]>?
let placeholder: LocalizedStringKey
let searchPlaceholder: LocalizedStringKey
let emptyText: LocalizedStringKey
let title: (Item) -> String
@State private var open = false
@Environment(\.isEnabled) private var isEnabled
@Environment(\.isInvalid) private var invalid
@Environment(\.colorScheme) private var colorSchemeimport SwiftUI
public struct VariantButtonStyle: ButtonStyle {
public enum Variant: CaseIterable, Sendable {
case `default`, outline, secondary, tinted, ghost, plain, destructive, link
}
public enum Size: CaseIterable, Sendable {
case `default`, xs, sm, lg, xl, icon, iconXs, iconSm, iconLg, iconXl
var height: CGFloat {
switch self {
case .xs, .iconXs: 24
case .sm, .iconSm: 32
case .default, .icon: 36
case .lg, .iconLg: 44import SwiftUI
extension EnvironmentValues {
@Entry var buttonGroup: Axis? = nil
@Entry var buttonGroupSize: CGSize = .zero
}
enum ButtonGroupSpace: Hashable {
case group
}
struct ButtonGroupFrame {
let bounds: Anchor<CGRect>
let outlined: Bool
}import PhosphorSwift
import SwiftUI
extension Shadow {
static let control = Shadow(color: .black.opacity(0.08), radius: 0.5, y: 0.5)
static let thumb = Shadow(color: .black.opacity(0.12), radius: 1.5, y: 1)
}
struct SelectionIndicator<Mark: View>: View {
let checked: Bool
let pressed: Bool
let cornerRadius: CGFloat
let mark: Mark
@Environment(\.isEnabled) private var isEnabled
@Environment(\.isInvalid) private var invalidimport PhosphorSwift
import SwiftUI
enum MenuPresentation: Sendable {
case system, popup
}
extension EnvironmentValues {
@Entry var menuPresentation: MenuPresentation = .system
@Entry var menuRadio = MenuRadioContext()
}
struct MenuRadioContext: @unchecked Sendable {
var selected: AnyHashable?
var select: @MainActor @Sendable (AnyHashable) -> Void = { _ in }
}import SwiftUI
extension EnvironmentValues {
@Entry public var isInvalid = false
@Entry var fieldInset = false
@Entry var fieldGroupInset = false
@Entry var fieldSetInset = false
}
extension View {
public func invalid(_ isInvalid: Bool = true) -> some View {
environment(\.isInvalid, isInvalid)
}
}
public enum FieldOrientation: CaseIterable, Sendable {import SwiftUI
extension EnvironmentValues {
@Entry public var hapticsEnabled = true
}
extension View {
public func haptics(_ enabled: Bool) -> some View {
environment(\.hapticsEnabled, enabled)
}
func hapticFeedback<Trigger: Equatable>(_ feedback: SensoryFeedback, trigger: Trigger) -> some View {
modifier(HapticFeedbackModifier(feedback: feedback, trigger: trigger) { _, _ in true })
}
func hapticFeedback<Trigger: Equatable>(import SwiftUI
public enum ItemVariant: CaseIterable, Sendable {
case `default`, outline, muted
}
public enum ItemSize: CaseIterable, Sendable {
case `default`, sm, xs
var horizontalPadding: CGFloat {
switch self {
case .default: 16
case .sm: 14
case .xs: 12
}
}import PhosphorSwift
import Observation
import SwiftUI
public enum PopupAlignment: Sendable, CaseIterable {
case start, center, end
}
struct OverlayDismiss: Sendable {
let action: @MainActor @Sendable () -> Void
@MainActor func callAsFunction() {
action()
}
}import PhosphorSwift
import SwiftUI
struct SelectContext: @unchecked Sendable {
var selected: AnyHashable?
var registering = false
var select: @MainActor @Sendable (AnyHashable) -> Void = { _ in }
}
extension EnvironmentValues {
@Entry var select = SelectContext()
}
struct SelectLabelsKey: PreferenceKey {
static var defaultValue: [AnyHashable: Text] { [:] }import SwiftUI
public struct Separator: View {
let orientation: Axis
public init(_ orientation: Axis = .horizontal) {
self.orientation = orientation
}
public var body: some View {
Rectangle()
.fill(Color.separator)
.frame(width: orientation == .vertical ? 1 : nil, height: orientation == .horizontal ? 1 : nil)
.frame(maxWidth: orientation == .horizontal ? .infinity : nil, maxHeight: orientation == .vertical ? .infinity : nil)
.accessibilityHidden(true)
}import SwiftUI
public enum TextVariant: CaseIterable, Sendable {
case `default`, h1, h2, h3, h4, p, blockquote, code, lead, large, small, muted
var style: TextStyle {
switch self {
case .h1: .xl3
case .h2: .xl2
case .h3: .xl
case .h4, .lead, .large: .lg
case .code, .small, .muted: .sm
default: .base
}
}- Add the files to your app target.
- Set
minSdkto 24 or higher and add the dependencies:
implementation(platform("androidx.compose:compose-bom:2026.09.00"))
implementation("androidx.compose.foundation:foundation")
implementation("androidx.compose.ui:ui")
implementation("com.adamglin:phosphor-icon-android:1.0.0")- Copy the theme files every view uses:
package com.esuiss.ui.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.dropShadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.shadow.Shadow as DropShadow
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.LineHeightStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpOffsetpackage com.esuiss.ui.theme
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
@Immutable
data class Colors(
val surface: Color,
val surfaceSecondary: Color,
val surfaceTertiary: Color,
val surfaceRaised: Color,
val label: Color,
val labelSecondary: Color,
val labelTertiary: Color,
val labelQuaternary: Color,- Copy the source and every file it uses:
package com.esuiss.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightInpackage com.esuiss.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShapepackage com.esuiss.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.Immutablepackage com.esuiss.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.selection.triStateToggleable
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Colorpackage com.esuiss.ui.components
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
val LocalContentStyle = compositionLocalOf { TextStyle.Default }
val LocalContentColor = compositionLocalOf { Color.Unspecified }
val LocalIconSize = compositionLocalOf { 20.dp }package com.esuiss.ui.components
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightpackage com.esuiss.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.LayoutScopeMarker
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextpackage com.esuiss.ui.components
import android.provider.Settings
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.text.selection.TextSelectionColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Sizepackage com.esuiss.ui.components
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.hapticfeedback.HapticFeedback
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
val LocalHapticsEnabled = staticCompositionLocalOf { true }
@Composable
fun ProvideHaptics(enabled: Boolean, content: @Composable () -> Unit) {
CompositionLocalProvider(LocalHapticsEnabled provides enabled, content = content)
}package com.esuiss.ui.components
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
import com.esuiss.ui.theme.EsuissTheme
@Composable
fun Icon(
imageVector: ImageVector,package com.esuiss.ui.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography
@Composablepackage com.esuiss.ui.components
import android.os.Build
import android.view.Window
import android.view.WindowManager
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.EnterExitState
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.slideInpackage com.esuiss.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightInpackage com.esuiss.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.theme.EsuissTheme
@Composable
fun Separator(- Update the
com.esuiss.uipackage names to match your project.
Usage
import { ComboboxTrigger, ComboboxInput, ComboboxContent, ComboboxList, ComboboxItem, ComboboxGroup, ComboboxLabel, ComboboxEmpty, ComboboxSeparator, ComboboxChips, ComboboxChip, ComboboxChipsInput } from "@/components/ui/combobox"<ComboboxDemo defaultValue="Expo" defaultOpen />Pass items to the root and render the filtered list with a function child of ComboboxList. For grouped items, render a ComboboxGroup per group with a ComboboxLabel and a ComboboxCollection. Add ComboboxEmpty for the no-results message.
Use value, defaultValue and onValueChange for the selection, and inputValue with onInputValueChange for the typed text. For object items, provide itemToStringLabel. filter, limit and locale tune matching.
With chips, create a ref with useComboboxAnchor(), attach it to ComboboxChips, and pass it to ComboboxContent as anchor so the list lines up with the chips field. On ComboboxInput, set showClear to add a clear button and showTrigger={false} to hide the caret.
Examples
Default


import * as React from "react"
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
function ComboboxDemo({
defaultValue = null,
defaultOpen,
disabled,
showClear,
labelledBy,
invalid,
}: {
defaultValue?: string | null
defaultOpen?: boolean
disabled?: boolean
showClear?: boolean
labelledBy?: string
invalid?: boolean
}) {
const [value, setValue] = React.useState<string | null>(defaultValue)
return (
<Combobox
items={frameworks}
value={value}
onValueChange={setValue}
defaultOpen={defaultOpen}
disabled={disabled}
>
<ComboboxInput
className="w-64"
placeholder="Select a framework"
showClear={showClear}
disabled={disabled}
invalid={invalid}
accessibilityLabelledBy={labelledBy}
/>
<ComboboxContent>
<ComboboxEmpty>No framework found.</ComboboxEmpty>
<ComboboxList>
{(item: string) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
export function ComboboxExample() {
return (
<ComboboxDemo />
)
}import EsuissUI
import SwiftUI
let comboboxFrameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
struct ComboboxDemo: View {
@State private var value: String?
init(initial: String? = nil) {
_value = State(initialValue: initial)
}
var body: some View {
Combobox(
comboboxFrameworks,
selection: $value,
placeholder: "Select a framework",
emptyText: "No framework found."
)
.frame(width: 256)
}
}import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Combobox
val ComboboxFrameworks = listOf("Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro", "Gatsby", "Expo")
@Composable
fun ComboboxDemo(
defaultValue: String? = null,
disabled: Boolean = false,
showClear: Boolean = false,
label: String? = null,
invalid: Boolean? = null,
) {
var value by rememberSaveable { mutableStateOf(defaultValue) }
Column {
Combobox(
items = ComboboxFrameworks,
value = value,
onValueChange = { value = it },
modifier = Modifier
.width(256.dp)
.then(if (label != null) Modifier.semantics { contentDescription = label } else Modifier),
placeholder = "Select a framework",
emptyText = "No framework found.",
showClear = showClear,
invalid = invalid,
enabled = !disabled,
)
}
}With value
Starts with a selected value.


import * as React from "react"
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
function ComboboxDemo({
defaultValue = null,
defaultOpen,
disabled,
showClear,
labelledBy,
invalid,
}: {
defaultValue?: string | null
defaultOpen?: boolean
disabled?: boolean
showClear?: boolean
labelledBy?: string
invalid?: boolean
}) {
const [value, setValue] = React.useState<string | null>(defaultValue)
return (
<Combobox
items={frameworks}
value={value}
onValueChange={setValue}
defaultOpen={defaultOpen}
disabled={disabled}
>
<ComboboxInput
className="w-64"
placeholder="Select a framework"
showClear={showClear}
disabled={disabled}
invalid={invalid}
accessibilityLabelledBy={labelledBy}
/>
<ComboboxContent>
<ComboboxEmpty>No framework found.</ComboboxEmpty>
<ComboboxList>
{(item: string) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
export function ComboboxWithValueExample() {
return (
<ComboboxDemo defaultValue="Expo" />
)
}import EsuissUI
import SwiftUI
struct ComboboxWithValueExample: View {
var body: some View {
ComboboxDemo(initial: "Expo")
}
}
let comboboxFrameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
struct ComboboxDemo: View {
@State private var value: String?
init(initial: String? = nil) {
_value = State(initialValue: initial)
}
var body: some View {
Combobox(
comboboxFrameworks,
selection: $value,
placeholder: "Select a framework",
emptyText: "No framework found."
)
.frame(width: 256)
}
}import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Combobox
@Composable
fun ComboboxWithValueExample() {
ComboboxDemo(defaultValue = "Expo")
}
val ComboboxFrameworks = listOf("Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro", "Gatsby", "Expo")
@Composable
fun ComboboxDemo(
defaultValue: String? = null,
disabled: Boolean = false,
showClear: Boolean = false,
label: String? = null,
invalid: Boolean? = null,
) {
var value by rememberSaveable { mutableStateOf(defaultValue) }
Column {
Combobox(
items = ComboboxFrameworks,
value = value,
onValueChange = { value = it },
modifier = Modifier
.width(256.dp)
.then(if (label != null) Modifier.semantics { contentDescription = label } else Modifier),
placeholder = "Select a framework",
emptyText = "No framework found.",
showClear = showClear,
invalid = invalid,
enabled = !disabled,
)
}
}With clear
A clear button through showClear.


import * as React from "react"
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
function ComboboxDemo({
defaultValue = null,
defaultOpen,
disabled,
showClear,
labelledBy,
invalid,
}: {
defaultValue?: string | null
defaultOpen?: boolean
disabled?: boolean
showClear?: boolean
labelledBy?: string
invalid?: boolean
}) {
const [value, setValue] = React.useState<string | null>(defaultValue)
return (
<Combobox
items={frameworks}
value={value}
onValueChange={setValue}
defaultOpen={defaultOpen}
disabled={disabled}
>
<ComboboxInput
className="w-64"
placeholder="Select a framework"
showClear={showClear}
disabled={disabled}
invalid={invalid}
accessibilityLabelledBy={labelledBy}
/>
<ComboboxContent>
<ComboboxEmpty>No framework found.</ComboboxEmpty>
<ComboboxList>
{(item: string) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
export function ComboboxWithClearExample() {
return (
<ComboboxDemo defaultValue="Remix" showClear />
)
}import EsuissUI
import SwiftUI
struct ComboboxWithClearExample: View {
var body: some View {
ComboboxDemo(initial: "Remix")
}
}
let comboboxFrameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
struct ComboboxDemo: View {
@State private var value: String?
init(initial: String? = nil) {
_value = State(initialValue: initial)
}
var body: some View {
Combobox(
comboboxFrameworks,
selection: $value,
placeholder: "Select a framework",
emptyText: "No framework found."
)
.frame(width: 256)
}
}import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Combobox
@Composable
fun ComboboxWithClearExample() {
ComboboxDemo(defaultValue = "Remix", showClear = true)
}
val ComboboxFrameworks = listOf("Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro", "Gatsby", "Expo")
@Composable
fun ComboboxDemo(
defaultValue: String? = null,
disabled: Boolean = false,
showClear: Boolean = false,
label: String? = null,
invalid: Boolean? = null,
) {
var value by rememberSaveable { mutableStateOf(defaultValue) }
Column {
Combobox(
items = ComboboxFrameworks,
value = value,
onValueChange = { value = it },
modifier = Modifier
.width(256.dp)
.then(if (label != null) Modifier.semantics { contentDescription = label } else Modifier),
placeholder = "Select a framework",
emptyText = "No framework found.",
showClear = showClear,
invalid = invalid,
enabled = !disabled,
)
}
}Grouped
Items in labelled groups with separators.


import * as React from "react"
import { Combobox, ComboboxCollection, ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxInput, ComboboxItem, ComboboxLabel, ComboboxList, ComboboxSeparator } from "@/components/ui/combobox"
interface Produce {
value: string
label: string
}
const produce: { value: string; items: Produce[] }[] = [
{
value: "Fruits",
items: [
{ value: "mango", label: "Mango" },
{ value: "banana", label: "Banana" },
{ value: "blueberry", label: "Blueberry" },
],
},
{
value: "Vegetables",
items: [
{ value: "carrot", label: "Carrot" },
{ value: "broccoli", label: "Broccoli" },
{ value: "spinach", label: "Spinach" },
],
},
]
function GroupedDemo() {
return (
<Combobox items={produce} itemToStringLabel={(item: Produce) => item.label}>
<ComboboxInput className="w-64" placeholder="Select produce" />
<ComboboxContent>
<ComboboxEmpty>No produce found.</ComboboxEmpty>
<ComboboxList>
{(group: (typeof produce)[number], index: number) => (
<React.Fragment key={group.value}>
{index > 0 ? <ComboboxSeparator /> : null}
<ComboboxGroup items={group.items}>
<ComboboxLabel>{group.value}</ComboboxLabel>
<ComboboxCollection>
{(item: Produce) => (
<ComboboxItem key={item.value} value={item}>
{item.label}
</ComboboxItem>
)}
</ComboboxCollection>
</ComboboxGroup>
</React.Fragment>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
export function ComboboxGroupedExample() {
return (
<GroupedDemo />
)
}import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Combobox
data class ComboboxProduce(val value: String, val label: String, val group: String)
val ComboboxProduceItems = listOf(
ComboboxProduce("mango", "Mango", "Fruits"),
ComboboxProduce("banana", "Banana", "Fruits"),
ComboboxProduce("blueberry", "Blueberry", "Fruits"),
ComboboxProduce("carrot", "Carrot", "Vegetables"),
ComboboxProduce("broccoli", "Broccoli", "Vegetables"),
ComboboxProduce("spinach", "Spinach", "Vegetables"),
)
@Composable
fun ComboboxGrouped() {
var value by rememberSaveable { mutableStateOf<String?>(null) }
Column {
Combobox(
items = ComboboxProduceItems,
value = ComboboxProduceItems.firstOrNull { it.value == value },
onValueChange = { value = it?.value },
modifier = Modifier.width(256.dp),
itemText = { it.label },
placeholder = "Select produce",
emptyText = "No produce found.",
groupBy = { it.group },
)
}
}Multiple
Multiple selection shown as removable chips.


import * as React from "react"
import { Combobox, ComboboxChip, ComboboxChips, ComboboxChipsInput, ComboboxContent, ComboboxEmpty, ComboboxItem, ComboboxList, useComboboxAnchor } from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
function MultipleDemo() {
const anchor = useComboboxAnchor()
const [value, setValue] = React.useState<string[]>(["Expo", "Astro"])
return (
<Combobox
multiple
items={frameworks}
value={value}
onValueChange={setValue}
>
<ComboboxChips ref={anchor} className="w-72">
{value.map((item) => (
<ComboboxChip key={item} value={item}>
{item}
</ComboboxChip>
))}
<ComboboxChipsInput placeholder="Add framework" />
</ComboboxChips>
<ComboboxContent anchor={anchor}>
<ComboboxEmpty>No framework found.</ComboboxEmpty>
<ComboboxList>
{(item: string) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
export function ComboboxMultipleExample() {
return (
<MultipleDemo />
)
}import EsuissUI
import SwiftUI
let comboboxFrameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
struct ComboboxMultipleDemo: View {
@State private var value = ["Expo", "Astro"]
var body: some View {
Combobox(
comboboxFrameworks,
selection: $value,
placeholder: "Add framework",
emptyText: "No framework found."
)
.frame(width: 288)
}
}import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.MultiCombobox
val ComboboxFrameworks = listOf("Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro", "Gatsby", "Expo")
@Composable
fun ComboboxMultiple() {
var values by rememberSaveable { mutableStateOf(listOf("Expo", "Astro")) }
Column {
MultiCombobox(
items = ComboboxFrameworks,
values = values,
onValuesChange = { values = it },
modifier = Modifier.width(288.dp),
placeholder = "Add framework",
emptyText = "No framework found.",
)
}
}With label
Linked to a Label with helper text.


import * as React from "react"
import { View } from "react-native"
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "@/components/ui/combobox"
import { Label } from "@/components/ui/label"
import { Text } from "@/components/ui/text"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
function ComboboxDemo({
defaultValue = null,
defaultOpen,
disabled,
showClear,
labelledBy,
invalid,
}: {
defaultValue?: string | null
defaultOpen?: boolean
disabled?: boolean
showClear?: boolean
labelledBy?: string
invalid?: boolean
}) {
const [value, setValue] = React.useState<string | null>(defaultValue)
return (
<Combobox
items={frameworks}
value={value}
onValueChange={setValue}
defaultOpen={defaultOpen}
disabled={disabled}
>
<ComboboxInput
className="w-64"
placeholder="Select a framework"
showClear={showClear}
disabled={disabled}
invalid={invalid}
accessibilityLabelledBy={labelledBy}
/>
<ComboboxContent>
<ComboboxEmpty>No framework found.</ComboboxEmpty>
<ComboboxList>
{(item: string) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
export function ComboboxWithLabelExample() {
return (
<View className="gap-2">
<Label nativeID="combobox-framework">Framework</Label>
<ComboboxDemo labelledBy="combobox-framework" />
<Text className="text-sm text-label-secondary">
Search and pick the framework you use.
</Text>
</View>
)
}import EsuissUI
import SwiftUI
struct ComboboxWithLabelExample: View {
var body: some View {
VStack(alignment: .leading, spacing: 8) {
FieldLabel("Framework")
.accessibilityHidden(true)
ComboboxDemo()
.accessibilityLabel(Text("Framework"))
Text("Search and pick the framework you use.")
.textStyle(.sm)
.foregroundStyle(Color.labelSecondary)
}
}
}
let comboboxFrameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
struct ComboboxDemo: View {
@State private var value: String?
init(initial: String? = nil) {
_value = State(initialValue: initial)
}
var body: some View {
Combobox(
comboboxFrameworks,
selection: $value,
placeholder: "Select a framework",
emptyText: "No framework found."
)
.frame(width: 256)
}
}import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Combobox
import com.esuiss.ui.components.Label
import com.esuiss.ui.components.Text
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography
val ComboboxFrameworks = listOf("Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro", "Gatsby", "Expo")
@Composable
fun ComboboxDemo(
defaultValue: String? = null,
disabled: Boolean = false,
showClear: Boolean = false,
label: String? = null,
invalid: Boolean? = null,
) {
var value by rememberSaveable { mutableStateOf(defaultValue) }
Column {
Combobox(
items = ComboboxFrameworks,
value = value,
onValueChange = { value = it },
modifier = Modifier
.width(256.dp)
.then(if (label != null) Modifier.semantics { contentDescription = label } else Modifier),
placeholder = "Select a framework",
emptyText = "No framework found.",
showClear = showClear,
invalid = invalid,
enabled = !disabled,
)
}
}
@Composable
fun ComboboxWithLabel() {
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Label("Framework")
ComboboxDemo(label = "Framework")
Text(
"Search and pick the framework you use.",
style = Typography.sm.copy(color = EsuissTheme.colors.labelSecondary),
)
}
}Disabled
A disabled combobox.


import * as React from "react"
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
function ComboboxDemo({
defaultValue = null,
defaultOpen,
disabled,
showClear,
labelledBy,
invalid,
}: {
defaultValue?: string | null
defaultOpen?: boolean
disabled?: boolean
showClear?: boolean
labelledBy?: string
invalid?: boolean
}) {
const [value, setValue] = React.useState<string | null>(defaultValue)
return (
<Combobox
items={frameworks}
value={value}
onValueChange={setValue}
defaultOpen={defaultOpen}
disabled={disabled}
>
<ComboboxInput
className="w-64"
placeholder="Select a framework"
showClear={showClear}
disabled={disabled}
invalid={invalid}
accessibilityLabelledBy={labelledBy}
/>
<ComboboxContent>
<ComboboxEmpty>No framework found.</ComboboxEmpty>
<ComboboxList>
{(item: string) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
export function ComboboxDisabledExample() {
return (
<ComboboxDemo defaultValue="Astro" disabled />
)
}import EsuissUI
import SwiftUI
struct ComboboxDisabledExample: View {
var body: some View {
ComboboxDemo(initial: "Astro")
.disabled(true)
}
}
let comboboxFrameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
struct ComboboxDemo: View {
@State private var value: String?
init(initial: String? = nil) {
_value = State(initialValue: initial)
}
var body: some View {
Combobox(
comboboxFrameworks,
selection: $value,
placeholder: "Select a framework",
emptyText: "No framework found."
)
.frame(width: 256)
}
}import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Combobox
@Composable
fun ComboboxDisabledExample() {
ComboboxDemo(defaultValue = "Astro", disabled = true)
}
val ComboboxFrameworks = listOf("Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro", "Gatsby", "Expo")
@Composable
fun ComboboxDemo(
defaultValue: String? = null,
disabled: Boolean = false,
showClear: Boolean = false,
label: String? = null,
invalid: Boolean? = null,
) {
var value by rememberSaveable { mutableStateOf(defaultValue) }
Column {
Combobox(
items = ComboboxFrameworks,
value = value,
onValueChange = { value = it },
modifier = Modifier
.width(256.dp)
.then(if (label != null) Modifier.semantics { contentDescription = label } else Modifier),
placeholder = "Select a framework",
emptyText = "No framework found.",
showClear = showClear,
invalid = invalid,
enabled = !disabled,
)
}
}Invalid
The invalid style with an error message.


import * as React from "react"
import { View } from "react-native"
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "@/components/ui/combobox"
import { Text } from "@/components/ui/text"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
function ComboboxDemo({
defaultValue = null,
defaultOpen,
disabled,
showClear,
labelledBy,
invalid,
}: {
defaultValue?: string | null
defaultOpen?: boolean
disabled?: boolean
showClear?: boolean
labelledBy?: string
invalid?: boolean
}) {
const [value, setValue] = React.useState<string | null>(defaultValue)
return (
<Combobox
items={frameworks}
value={value}
onValueChange={setValue}
defaultOpen={defaultOpen}
disabled={disabled}
>
<ComboboxInput
className="w-64"
placeholder="Select a framework"
showClear={showClear}
disabled={disabled}
invalid={invalid}
accessibilityLabelledBy={labelledBy}
/>
<ComboboxContent>
<ComboboxEmpty>No framework found.</ComboboxEmpty>
<ComboboxList>
{(item: string) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
export function ComboboxInvalidExample() {
return (
<View className="gap-2">
<ComboboxDemo invalid />
<Text className="text-sm text-danger">Please select a framework.</Text>
</View>
)
}import EsuissUI
import SwiftUI
struct ComboboxInvalidExample: View {
var body: some View {
VStack(alignment: .leading, spacing: 8) {
ComboboxDemo()
.invalid()
Text("Please select a framework.")
.textStyle(.sm)
.foregroundStyle(Color.danger)
}
}
}
let comboboxFrameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
"Gatsby",
"Expo",
]
struct ComboboxDemo: View {
@State private var value: String?
init(initial: String? = nil) {
_value = State(initialValue: initial)
}
var body: some View {
Combobox(
comboboxFrameworks,
selection: $value,
placeholder: "Select a framework",
emptyText: "No framework found."
)
.frame(width: 256)
}
}import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Combobox
import com.esuiss.ui.components.Text
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography
val ComboboxFrameworks = listOf("Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro", "Gatsby", "Expo")
@Composable
fun ComboboxDemo(
defaultValue: String? = null,
disabled: Boolean = false,
showClear: Boolean = false,
label: String? = null,
invalid: Boolean? = null,
) {
var value by rememberSaveable { mutableStateOf(defaultValue) }
Column {
Combobox(
items = ComboboxFrameworks,
value = value,
onValueChange = { value = it },
modifier = Modifier
.width(256.dp)
.then(if (label != null) Modifier.semantics { contentDescription = label } else Modifier),
placeholder = "Select a framework",
emptyText = "No framework found.",
showClear = showClear,
invalid = invalid,
enabled = !disabled,
)
}
}
@Composable
fun ComboboxInvalid() {
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
ComboboxDemo(invalid = true)
Text("Please select a framework.", style = Typography.sm.copy(color = EsuissTheme.colors.danger))
}
}API Reference
ComboboxTrigger
Round button that opens the list.
React.ComponentProps<typeof ComboboxPrimitive.Trigger>- Type
React.ReactNode- Default
- —
ComboboxInput
Text field with caret trigger and optional clear button.
React.ComponentProps<typeof ComboboxPrimitive.Input>- Type
string- Default
- —
- Type
React.ReactNode- Default
- —
- About
- Shows the caret button. Defaults to
true. - Type
boolean- Default
- true
- About
- Shows a clear button when there is text or a value.
- Type
boolean- Default
- false
- About
- Shows the danger border; also read from a surrounding Field.
- Type
boolean- Default
- —
ComboboxContent
Floating popup for the list.
React.ComponentProps<typeof ComboboxPrimitive.Popup>PositionerProps- About
- Name of the portal host to render into.
- Type
string- Default
- —
ComboboxList
Scrollable list of items.
React.ComponentProps<typeof ComboboxPrimitive.List>ComboboxItem
Selectable option with a check mark when selected.
React.ComponentProps<typeof ComboboxPrimitive.Item>- Type
React.ReactNode- Default
- —
ComboboxGroup
Group of items.
React.ComponentProps<typeof ComboboxPrimitive.Group>ComboboxLabel
Heading for a group.
React.ComponentProps<typeof ComboboxPrimitive.GroupLabel>ComboboxEmpty
Message shown when nothing matches.
React.ComponentProps<typeof ComboboxPrimitive.Empty>ComboboxSeparator
Line between groups.
React.ComponentProps<typeof ComboboxPrimitive.Separator>ComboboxChips
Field that holds chips for multiple selection.
React.ComponentProps<typeof ComboboxPrimitive.Chips>- About
- Shows the danger border.
- Type
boolean- Default
- —
ComboboxChip
Selected value with a remove button.
React.ComponentProps<typeof ComboboxPrimitive.Chip>- About
- Shows the remove button. Defaults to
true. - Type
boolean- Default
- true
ComboboxChipsInput
Text input inside the chips field.
React.ComponentProps<typeof ComboboxPrimitive.Input>Accessibility
- The input has the
comboboxrole withexpandedanddisabledstate. - Items have the
optionrole withselectedanddisabledstate; the list has thelistrole. - The empty message is a polite live region.
- The trigger, clear and chip remove buttons are labelled "Show options", "Clear" and "Remove".
Notes
- Uses
bg-control,bg-surface-raised,border-focusandborder-dangertokens; light and dark follow the system appearance. - Fade animations respect the system Reduce Motion setting.