suiss/ui · Component
Select
A button that opens a list of options so people can pick one value.
Select is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Select wraps the select primitive of the chosen base. SelectTrigger shows the current choice through SelectValue and a chevron icon; SelectContent renders the popup in a portal, positioned against the trigger, and holds SelectItem options. Use SelectGroup with a SelectLabel to title a set of options, and SelectSeparator to divide groups.
A highlight pill slides between options as the highlighted item changes, and the selected item shows a check mark. Use Select when people choose one value from a fixed list. For a few always-visible options, consider ToggleGroup or RadioGroup.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
- Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a Select:
Examples
Open
Renders the popup open on mount with a value already selected.
With value
Set defaultValue on Select to start with a value, so the trigger shows its label.
Small
Set size="sm" on SelectTrigger for the compact trigger.
Large
Set size="lg" on SelectTrigger for the 54px trigger used in forms such as sign-in pages.
Grouped
Wrap options in a SelectGroup with a SelectLabel, and put a SelectSeparator between groups.
With icons
Places an icon before each option's label.
Disabled
Set disabled on Select so it can't be opened.
Set isDisabled on Select so it can't be opened.
Invalid
Set aria-invalid on SelectTrigger to show an error state.
Set isInvalid on Select to show an error state.
Accessibility
- The trigger has the
comboboxrole and the popup list has thelistboxrole; each item is anoptionwitharia-selectedon the chosen one. - Give the trigger an accessible name, such as
aria-labelor an associated label.
- The trigger is a button that opens a
listbox; each item is anoptionwitharia-selectedon the chosen one. - Name the select with
aria-labelonSelect, or with an associated label.
- When the popup opens, focus moves to the selected option. Arrow keys move between options and
Enterselects. Escapecloses the popup without changing the value, and focus returns to the trigger.- A
SelectGroupwith aSelectLabelis exposed as a namedgroup.
API Reference
Select
The root that holds the selected value and the open state.
Also accepts the props of the primitive part it wraps.
Pass items as { value, label } pairs so SelectValue can show the label for the chosen value, even before the popup opens. Use defaultValue for an uncontrolled select, or value with onValueChange to control it.
Use defaultValue for an uncontrolled select, or value with onValueChange to control it.
Use defaultValue for an uncontrolled select, or value with onChange to control it.
SelectGroup
Groups related options; label it with a SelectLabel.
Also accepts the props of the primitive part it wraps.
SelectValue
Shows the selected option's label, or the placeholder, inside the trigger.
| Prop | Type | Default |
|---|---|---|
placeholder | React.ReactNode | - |
Also accepts the props of the primitive part it wraps.
placeholder is shown until a value is chosen.
SelectTrigger
The button that opens the popup and displays the current value.
| Prop | Type | Default |
|---|---|---|
size | "sm" | "default" | "lg" | "default" |
Also accepts the props of the primitive part it wraps.
The lg size is 54px tall with 17px text, the default size is 44px tall, and sm is 36px with smaller corners. The trigger sets data-size and styles its placeholder, invalid and disabled states; invalid triggers use the destructive color.
SelectContent
The positioned popup that holds the option list and scroll arrows.
| Prop | Type | Default |
|---|---|---|
side | "top" | "bottom" | "left" | "right" | "inline-start" | "inline-end" | "bottom" |
sideOffset | number | 4 |
align | "start" | "center" | "end" | "center" |
alignOffset | number | 0 |
alignItemWithTrigger | boolean | false |
| Prop | Type | Default |
|---|---|---|
position | "popper" | "item-aligned" | "popper" |
side | "top" | "right" | "bottom" | "left" | "bottom" |
sideOffset | number | 4 |
align | "start" | "center" | "end" | "center" |
alignOffset | number | 0 |
| Prop | Type | Default |
|---|---|---|
placement | Placement | "bottom" |
offset | number | 4 |
crossOffset | number | 0 |
Also accepts the props of the primitive parts it wraps.
The popup opens below the trigger by default. sideOffset is the gap to the trigger and alignOffset shifts the popup along the alignment axis, both in pixels. Set alignItemWithTrigger to place the popup so the selected item sits over the trigger.
The popup opens below the trigger by default. position="popper" places it next to the trigger, and item-aligned places the selected item over the trigger. side, sideOffset, align and alignOffset apply in the popper position; the offsets are in pixels.
The popup opens below the trigger by default. offset is the gap to the trigger and crossOffset shifts the popup along the cross axis, both in pixels.
A highlight pill slides between options as the highlighted item changes. The animation is turned off when reduced motion is preferred.
SelectLabel
A heading that names a SelectGroup.
Also accepts the props of the primitive part it wraps.
SelectItem
A selectable option, with a check mark when selected.
| Prop | Type | Default |
|---|---|---|
value | string | - |
Also accepts the props of the primitive part it wraps.
value is required. It is the value the select reports when this item is chosen.
SelectSeparator
A thin line that divides groups of options.
Also accepts the props of the primitive part it wraps.
SelectScrollUpButton
An arrow that scrolls the list up when it overflows; rendered by SelectContent.
Also accepts the props of the primitive part it wraps.
SelectScrollDownButton
An arrow that scrolls the list down when it overflows; rendered by SelectContent.
Also accepts the props of the primitive part it wraps.
Each part sets a data-slot, such as select-trigger, select-item or select-highlight, for styling.
Web preview
Select is built on the select primitive. SelectTrigger is a pressable field with the combobox role and an up-down caret. SelectContent renders in a portal, positioned next to the trigger, and fades in and out with Reanimated. The list matches the trigger width.
The trigger comes in two sizes, default and sm. Use Select for picking one value from a short list; for a list that needs searching, use Combobox.
Installation
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/select.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/select.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/select.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Default
Web preview
With value
A select that starts with a chosen value.
Web preview
Small
The sm trigger size.
Web preview
Large
The lg trigger size, 54 tall with 17 point text.
Web preview
Grouped
Two labeled groups divided by a separator.
Web preview
With label
A select labeled by a Label through accessibilityLabelledBy, with helper text.

Disabled
A disabled select with a value.
Web preview
Invalid
The invalid state with an error message.
Web preview
Accessibility
- The trigger has the
comboboxrole and reports its expanded and disabled states. - The list has the
listrole; each item has theoptionrole, uses its label asaccessibilityLabeland reports selected and disabled states. - Groups have the
grouprole and are labeled by theirSelectLabel. - Label the trigger with
accessibilityLabelledBypointing at aLabel'snativeID, or withaccessibilityLabel. - The Android back button and the VoiceOver escape gesture close the list.
API Reference
Select
The root that holds the selected value and the open state.
| Prop | Type | Default |
|---|---|---|
items | SelectItems | - |
value | Value | Value[] | null | - |
defaultValue | Value | Value[] | null | - |
onValueChange | (value, details) => void | - |
multiple | boolean | false |
open | boolean | - |
defaultOpen | boolean | false |
onOpenChange | (open: boolean, details) => void | - |
modal | boolean | true |
disabled | boolean | false |
readOnly | boolean | false |
Control the value with value and onValueChange, or start from defaultValue. Pass the full option list as items so SelectValue can show the label of the current value. Set multiple to allow several values, and readOnly to show the value without allowing changes. modal blocks interaction with the rest of the screen while open.
SelectGroup
Groups related items.
Also accepts the props of React.ComponentProps<typeof SelectPrimitive.Group>.
SelectValue
Shows the selected label or the placeholder.
Also accepts the props of React.ComponentProps<typeof SelectPrimitive.Value>.
placeholder is shown until a value is chosen.
SelectTrigger
Pressable field that opens the list.
| Prop | Type | Default |
|---|---|---|
children | React.ReactNode | - |
size | "default" | "sm" | "lg" | "default" |
invalid | boolean | - |
Also accepts the props of React.ComponentProps<typeof SelectPrimitive.Trigger>.
invalid shows the destructive border, and falls back to the invalid state of an enclosing field. The trigger draws the same outlined field as Input.
SelectContent
Floating list rendered in a portal.
| Prop | Type | Default |
|---|---|---|
portalHost | string | - |
Also accepts the props of React.ComponentProps<typeof SelectPrimitive.Popup>, PositionerProps.
portalHost names the portal host to render into. On iOS the list renders inside a FullWindowOverlay from react-native-screens, so it appears above native modals.
SelectLabel
Heading for a group.
Also accepts the props of React.ComponentProps<typeof SelectPrimitive.GroupLabel>.
SelectItem
One option, with a check mark when selected.
| Prop | Type | Default |
|---|---|---|
children | React.ReactNode | - |
Also accepts the props of React.ComponentProps<typeof SelectPrimitive.Item>.
Give each item a value and a label; the label is shown when no children are passed. The Option type ({ value, label }) is also exported.
SelectSeparator
Line between groups.
Also accepts the props of React.ComponentProps<typeof SelectPrimitive.Separator>.
SelectSize
Values: .default, .sm, .lg.
SelectField
| Parameter | Type | Default |
|---|---|---|
selection | Binding<Value?> | - |
placeholder | LocalizedStringKey | "Select" |
size | Size: .default | .sm | .lg | .default |
content | () -> Content | - |
SelectItem
One option, with a check mark when selected.
| Parameter | Type | Default |
|---|---|---|
_ title | LocalizedStringKey | - |
value | Value | - |
verbatim | String | - |
Overloads: init(_:value:), init(verbatim:value:).
SelectGroup
Groups related items.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
SelectLabel
Heading for a group.
| Parameter | Type | Default |
|---|---|---|
_ title | LocalizedStringKey | - |
SelectSeparator
Line between groups.
Takes no parameters.
SelectSize
Values: Default, Sm, Lg.
SelectOption
| Parameter | Type | Default |
|---|---|---|
value | String | - |
label | String | - |
enabled | Boolean | true |
Select
The root that holds the selected value and the open state.
| Parameter | Type | Default |
|---|---|---|
value | String? | - |
onValueChange | (String) -> Unit | - |
options | List<SelectOption> | - |
modifier | Modifier | Modifier |
placeholder | String | "" |
size | SelectSize: Default | Sm | Lg | SelectSize.Default |
invalid | Boolean? | null |
enabled | Boolean | true |
side | PopupSide | PopupSide.Bottom |
align | PopupAlign | PopupAlign.Center |
sideOffset | Dp | 4.dp |
displayValue | String? | - |
content | @Composable ColumnScope.() -> Unit | - |
Overloads: Select(value, onValueChange, options), Select(value, onValueChange, displayValue, content).
SelectGroup
Groups related items.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable ColumnScope.() -> Unit | - |
SelectLabel
Heading for a group.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
SelectItem
One option, with a check mark when selected.
| Parameter | Type | Default |
|---|---|---|
value | String | - |
text | String | - |
modifier | Modifier | Modifier |
enabled | Boolean | true |
SelectSeparator
Line between groups.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
