Select

One value picked from a list and held on the trigger: the input's field over the menu's popup and rows, opening with the chosen row level with the value.

01Preview

01
Full screen

02Installation

npx shadcn@latest add https://aiellie.app/r/select.json

03API reference

19
From the Base UI documentation

Groups all parts of the select. Doesn't render its own HTML element.

Props

PropTypeDefaultDescription
namestring-Identifies the field when a form is submitted.
defaultValueValue[] | Value | null-The uncontrolled value of the select when it's initially rendered. To render a controlled select, use the value prop instead.
valueValue[] | Value | null-The value of the select. Use when controlled.
onValueChange((value: Value[] | Value | null, eventDetails: Select.Root.ChangeEventDetails) => void)-Event handler called when the value of the select changes.
defaultOpenbooleanfalseWhether the select popup is initially open. To render a controlled select popup, use the open prop instead.
openboolean-Whether the select popup is currently open.
onOpenChange((open: boolean, eventDetails: Select.Root.ChangeEventDetails) => void)-Event handler called when the select popup is opened or closed.
highlightItemOnHoverbooleantrueWhether moving the pointer over items should highlight them. Disabling this prop allows CSS :hover to be differentiated from the :focus (data-highlighted) state.
actionsRefReact.RefObject<Select.Root.Actions | null>-A ref to imperative actions. unmount: Manually unmounts the select. Call this after any externally controlled closing animation finishes.
autoCompletestring-Provides a hint to the browser for autofill.
formstring-Identifies the form that owns the hidden input. Useful when the select is rendered outside the form.
isItemEqualToValue((itemValue: Value, value: Value) => boolean)-Custom comparison logic used to determine if a select item value matches the current selected value. Useful when item values are objects without matching referentially. Defaults to Object.is comparison.
itemToStringLabel((itemValue: Value) => string)-When the item values are objects (<Select.Item value={object}>), this function converts the object value to a string representation for display in the trigger. If the shape of the object is { value, label }, the label will be used automatically without needing to specify this prop.
itemToStringValue((itemValue: Value) => string)-When the item values are objects (<Select.Item value={object}>), this function converts the object value to a string representation for form submission. If the shape of the object is { value, label }, the value will be used automatically without needing to specify this prop.
itemsRecord<string, React.ReactNode> | ({ label: React.ReactNode; value: any })[] | Group[]-Data structure of the items rendered in the select popup. When specified, <Select.Value> renders the label of the selected item instead of the raw value.
modalbooleantrueDetermines if the select enters a modal state when open. true: user interaction is limited to the select: document page scroll is locked and pointer interactions on outside elements are disabled.false: user interaction with the rest of the document is allowed. On touch devices, a true modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior.
multiplebooleanfalseWhether multiple items can be selected.
onOpenChangeComplete((open: boolean) => void)-Event handler called after any animations complete when the select popup is opened or closed.
disabledbooleanfalseWhether the component should ignore user interaction.
readOnlybooleanfalseWhether the user should be unable to choose a different option from the select popup.
requiredbooleanfalseWhether the user must choose a value before submitting a form.
inputRefReact.Ref<HTMLInputElement>-A ref to access the hidden input element.
idstring-The id of the Select.
childrenReact.ReactNode--