suiss/ui ยท Pattern
Search Picker
A searchable single-choice picker that renders a Combobox on desktop and a search drawer on mobile.
Search Picker is an open-source pattern 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.
SearchPicker lets the user find and choose one item from a long list. On desktop it renders a suiss/ui Combobox: the field itself is the search input, and the list filters as the user types. On mobile (below 48rem, via useIsMobile) it renders a field-style button that opens a Drawer with a swipe handle and a searchable Command menu. Choosing an item closes the drawer.
Use it for countries, cities, users and other lists too long to scan; for short lists, use Picker.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Examples
With value
Set defaultValue to start with a selected item.
Grouped
Give items a group to list them under group headings in both presentations. Search filters across groups.
With title
Set title to show a visible heading at the top of the mobile drawer. Without it, the drawer title is visually hidden.
With close button
Set showCloseButton to add a close button to the mobile drawer.
With close label
Set closeLabel to use a Cancel text button for the mobile close button in place of the icon.
Disabled
Set disabled to disable the field.
Invalid
Set aria-invalid to mark the field invalid and apply the error style.
Controlled
Control the value with value and onValueChange.
Floating
Set floating to inset the mobile drawer from the screen edges.
Accessibility
- On desktop the field has the
comboboxrole and controls alistbox. The selected option hasaria-selected, disabled options havearia-disabled, and groups are exposed asgroupelements named by their heading. - Escape closes the desktop list.
- On mobile, the drawer is titled by
title,placeholderoraria-label, and focus moves to the search input when it opens.
API Reference
SearchPicker
The complete searchable picker, rendered from the items array.
| Prop | Type | Default |
|---|---|---|
items | SearchPickerItem[] | Required |
value | string | null | - |
defaultValue | string | null | - |
onValueChange | (value: string | null) => void | - |
placeholder | string | - |
searchPlaceholder | string | "Search..." |
emptyText | string | "No results found." |
title | string | - |
disabled | boolean | - |
floating | boolean | - |
showCloseButton | boolean | false |
closeLabel | string | - |
id | string | - |
className | string | - |
aria-invalid | boolean | - |
aria-label | string | - |
aria-describedby | string | - |
Each item in items has a value, a label, and an optional group and disabled flag; the SearchPickerItem type is exported. The value is uncontrolled by default; use defaultValue, or value with onValueChange to control it. The value is null when nothing is selected.
searchPlaceholder, title, floating, showCloseButton and closeLabel affect only the mobile drawer. On desktop the field itself is the search input and shows placeholder. Mobile search matches against each item's label. id and className go to the input on desktop and to the trigger button on mobile.
The parts set data-slot="search-picker", search-picker-trigger (mobile) and search-picker-content for styling. The mobile trigger has data-placeholder while nothing is selected, and the selected command item has data-checked.
Web preview
SearchPicker renders a field-style DrawerTrigger with the selected label and an up-down caret. Pressing it opens a Drawer with a search input and a scrollable list of options.
Typing filters options by label, case-insensitively. Options with a group are shown under a group heading. Choosing an option selects it, closes the drawer and clears the search. Use it when the list is too long to scan, such as countries, cities or frameworks.
Installation
-
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
With value
Starts with a preset selection via defaultValue.
Starts with a preset selection.
Web preview
Grouped
Cities grouped by country, with custom placeholders.
Web preview
With title
Adds a heading to the drawer with title.
Web preview
With close button
Shows a close button in the drawer.
Web preview
With close label
Labels the close button Cancel with closeLabel.
Web preview
Disabled
A disabled field that cannot open the drawer.
Web preview
Invalid
Shows the error border and tint with invalid.
Web preview
Controlled
Holds the value in state and prints the selection below.
Web preview
Floating
Detaches the drawer from the screen edges.
Web preview
The React Native tab shows 1 more example.
Accessibility
- Each option is a button that exposes
selectedanddisabledstates. - Each group has the
grouprole and is labelled by its name. - The search input is labelled by
searchPlaceholder. - Without a
title, the drawer is labelled by the placeholder oraccessibilityLabel.
API Reference
SearchPicker
| Prop | Type | Default |
|---|---|---|
items | SearchPickerItem[] | Required |
value | string | null | - |
defaultValue | string | null | - |
onValueChange | (value: string | null) => void | - |
placeholder | string | - |
searchPlaceholder | string | "Search..." |
emptyText | string | "No results found." |
title | string | - |
disabled | boolean | - |
floating | boolean | - |
showCloseButton | boolean | false |
closeLabel | string | - |
invalid | boolean | - |
className | string | - |
accessibilityLabel | string | - |
accessibilityLabelledBy | string | - |
Pass items as an array of { value, label, group?, disabled? }; the SearchPickerItem type is exported. Use it uncontrolled with defaultValue, or controlled with value and onValueChange; the value is a string or null. emptyText shows when nothing matches.
searchPlaceholder is also the label of the search input, which disables autocorrect and autocapitalization. The list stays between 40% and 60% of the window height, and taps work while the keyboard is open.
SearchPickerItem
| Parameter | Type | Default |
|---|---|---|
value | String | - |
label | String | - |
group | String? | nil |
disabled | Bool | false |
| Property | Type |
|---|---|
value | String |
label | String |
group | String? |
disabled | Bool |
id | String |
SearchPicker
The complete searchable picker, rendered from the items array.
| Parameter | Type | Default |
|---|---|---|
items | [SearchPickerItem] | - |
selection | Binding<String?> | - |
placeholder | LocalizedStringKey? | nil |
searchPlaceholder | LocalizedStringKey | "Search..." |
emptyText | LocalizedStringKey | "No results found." |
title | LocalizedStringKey? | nil |
showCloseButton | Bool | false |
closeLabel | LocalizedStringKey? | nil |
SearchPickerItem
| Parameter | Type | Default |
|---|---|---|
value | String | - |
label | String | - |
group | String? | null |
enabled | Boolean | true |
SearchPicker
The complete searchable picker, rendered from the items array.
| Parameter | Type | Default |
|---|---|---|
items | List<SearchPickerItem> | - |
value | String? | - |
onValueChange | (String) -> Unit | - |
modifier | Modifier | Modifier |
placeholder | String | "" |
searchPlaceholder | String | "Search..." |
emptyText | String | "No results found." |
title | String? | null |
enabled | Boolean | true |
invalid | Boolean? | null |
floating | Boolean | false |
showCloseButton | Boolean | false |
closeLabel | String? | null |