Picks one option from a set. SelectMenu owns the popup and the options, SelectTrigger is the trigger in a form; more than 10 options get a search row (see Combobox).
Status: stable · Components: SelectTrigger, SelectMenu
Import
Section titled “Import”import { SelectTrigger, SelectMenu } from 'nacre'import { signal } from 'nsh'import { SelectMenu, SelectTrigger } from 'nacre'
const LANGS = [ { value: 'zh', label: '简体中文' }, { value: 'hk', label: '繁體中文' }, { value: 'en', label: 'English' },]
const labelOf = (value: string) => LANGS.find((o) => o.value === value)?.label
export function SelectUsage() { const lang = signal('zh') return ( <SelectMenu testID="demo-select-lang" accessibilityLabel="Language" options={LANGS} value={lang()} onChange={(value) => lang.set(value)} searchable={false} trigger={(open) => <SelectTrigger class="w-40" expanded={open()} value={labelOf(lang())} accessibilityLabel="Language" />} /> )}Examples
Section titled “Examples”States
Section titled “States”Placeholder, invalid and disabled. Pair invalid with a Field that says what is wrong, not the red border alone.
import { View } from 'nsh'import { SelectTrigger } from 'nacre'
export function SelectStates() { return ( <View class="flex-row flex-wrap items-center gap-2"> <SelectTrigger class="w-40" placeholder="Choose…" accessibilityLabel="Category" /> <SelectTrigger class="w-40" placeholder="Required" invalid accessibilityLabel="Status" /> <SelectTrigger class="w-40" value="Resolved" disabled accessibilityLabel="Result" /> </View> )}The same size steps as TextField and Button; controls in one row share one step.
import { View } from 'nsh'import { SelectTrigger } from 'nacre'
export function SelectSizes() { return ( <View class="gap-2"> {(['xs', 'sm', 'md', 'lg'] as const).map((size) => ( <SelectTrigger class="w-40" size={size} value="简体中文" accessibilityLabel={'Language' + ` ${size}`} /> ))} </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Space / Return / ↓ | Open |
| ↑ ↓ | Move between options |
| Return | Choose and close |
| Esc | Close; the focus goes back to the trigger |
Accessibility
Section titled “Accessibility”- The trigger reads as “field: value” (“Language: English”), and as expanded while open.
- accessibilityLabel is required: the field’s name.
Do / Don’t
Section titled “Do / Don’t”Do
- 5–10 mutually exclusive options
- In a form, pair it with a Field for the label and the error
Don’t
- Use it for 2–5 options that should all be visible at once (use Segmented)
- Offer more than 10 options without search (use Combobox)
SelectTrigger
Section titled “SelectTrigger”| Prop | Type | Default | Description |
|---|---|---|---|
value |
string | null |
— | Text for the selected value. An empty value shows the placeholder. |
placeholder |
string |
— | Text to show when the field has no value. |
prefix |
string |
— | Muted text before the value, such as a field name. |
leading |
JSX.Element |
— | Element before the value, such as an icon or status dot. |
trailing |
JSX.Element |
— | Replaces the arrow. For a clear action, reserve this space and place the clear button outside the trigger. |
variant |
'field' | 'filled' | 'ghost' |
'field' |
Use field in a form, filled for a toolbar filter, or ghost for a text-only trigger. |
size |
'xs' | 'sm' | 'md' | 'lg' |
'sm' |
Desktop heights are 24, 28, 32 and 36 points from xs to lg. Touch uses the corresponding device tokens. |
invalid |
boolean |
— | Marks the field as invalid visually and for assistive technology. |
disabled |
boolean |
— | Disables the trigger. |
block |
boolean |
— | Fill the row. Pair with the block prop on SelectMenu. |
class |
string |
— | Additional layout or width classes. |
expanded |
boolean |
— | Reflects the current open state in the appearance and accessible state. |
testID |
string |
— | Test identifier for the trigger. |
valueTestID |
string |
— | Test identifier for the displayed value. |
accessibilityLabel |
string |
— | Field name spoken before the current value. Supply it when there is no visible label. |
onLayout |
(event: { bounds: { size: { width: number } } }) => void |
— | Called when the trigger is measured. |
viewRef |
(node: ViewRef) => void |
— | Provides the trigger node for restoring focus. |
* required
SelectMenu
Section titled “SelectMenu”| Prop | Type | Default | Description |
|---|---|---|---|
testID * |
string |
— | Base test identifier for the menu and its options. |
accessibilityLabel * |
string |
— | Spoken field name and title of the touch sheet. |
options * |
readonly ComboboxOption[] |
— | Choices in display order. |
value * |
string |
— | The currently selected option value. |
onChange * |
(value: string) => void |
— | Called when a different option is selected. |
trigger * |
JSX.Element | ((open: () => boolean) => JSX.Element) |
— | Element that opens the menu. The function form receives its open state to pass to SelectTrigger.expanded. |
minWidth |
number |
— | Minimum popup width. By default it matches the trigger and grows for long content, up to 320 points. |
searchable |
boolean |
— | Show the search field. By default it appears for more than ten options. |
placement |
'top' | 'bottom' |
'bottom' |
Open below the trigger by default. Use top for a field near the bottom of a window. |
disabled |
boolean |
— | Prevents the menu from opening. Set disabled on the trigger to show its disabled appearance. |
block |
boolean |
— | Fill the row. The trigger also needs flexible width. |
* required