Picker
Picker is a control for selecting from a set of mutually exclusive values. Picker displays a list of options and allows the user to select one.
Picker is a control for selecting from a set of mutually exclusive values. Picker displays a list of options and allows the user to select one.
Examples
Basic Usage
Preview unavailable for this example in the static docs build.
Show code
const PickerDemo = () => {
const [selected, setSelected] = useState<string | number>()
return (
<VStack spacing={16}>
<Text>Selected: {selected || 'None'}</Text>
<Picker
selection={selected}
onSelectionChange={setSelected}
options={options}
placeholder="Choose an option"
/>
<Picker
selection={selected}
onSelectionChange={setSelected}
options={options}
disabled
/>
</VStack>
)
}API
| Prop | Type | Required | Description |
|---|---|---|---|
selection | string | number | No | SwiftUI-style alias for the currently selected value. |
selectedValue | string | number | No | The currently selected value. |
defaultSelection | string | number | No | SwiftUI-style alias for the initial uncontrolled selection. |
defaultSelectedValue | string | number | No | The initial uncontrolled selection. |
onSelectionChange | (value: string | number) => void | No | SwiftUI-style alias fired when the selection changes. |
onValueChange | (value: string | number) => void | No | Callback fired when the selection changes. |
options | IPickerOption[] | Yes | The list of options to display. |
placeholder | string | No | Placeholder text when no option is selected. |
disabled | boolean | No | Whether the picker is disabled. Default: false |
Inherits additional props from Omit<
IBaseElementComponent<'select'>,
'value' | 'defaultValue' | 'onChange' | 'children' | 'disabled' | 'multiple' | 'size'
>.
Overview
Picker is a control for selecting from a set of mutually exclusive values. Picker displays a list of options and allows the user to select one.
SwiftUI Correspondence: Similar to SwiftUI's Picker.
Notes
- Picker requires an array of options with
valueandlabel - Picker supports SwiftUI-style controlled mode with
selectionandonSelectionChange selectedValueandonValueChangeremain available as React-friendly aliases- Use
defaultSelectionfor an initial uncontrolled value - Picker can be disabled with the
disabledprop - Use
placeholderto indicate no selection; it is rendered as a hidden placeholder option - Selection callbacks return the original option value type
- Picker automatically handles option rendering and selection
- Option values must be unique after string coercion
- The empty string is reserved for the placeholder state and cannot be used as a real option value
Best Practices
- Clear options: Use descriptive labels for each option
- Default selection: Consider providing a default selected value
- Validation: Validate selection when required
- Accessibility: Ensure Picker is keyboard accessible
- Mobile: Test picker behavior on mobile devices
PhotosPicker
PhotosPicker opens an image-only asset chooser and forwards selected files, keeping SwiftUI's media selection intent while relying on the browser's native file picker.
Popover
Popover presents lightweight content anchored to another control. It aligns with SwiftUI's `popover` presentation while keeping web-friendly dialog semantics.