Select API
- Component status:
-
stable
Import
Section titled “Import”import { Select } from "@stratakit/bricks";// ORimport * as Select from "@stratakit/bricks/Select";Select.Root
Section titled “Select.Root”Compound component for a select element, which allows the user to select a value from a list of options.
Use with the Field components to automatically handle ID associations for
labels and descriptions:
<Field.Root> <Field.Label>Fruit</Field.Label> <Field.Control render={(controlProps) => ( <Select.Root> <Select.HtmlSelect name="fruit" {...controlProps}> <option value="kiwi">Kiwi</option> <option value="mango">Mango</option> <option value="papaya">Papaya</option> </Select.HtmlSelect> </Select.Root> )} /></Field.Root>Without the Field components you will need to manually associate labels,
descriptions, etc.:
<Label htmlFor="fruit">Fruit</Label><Description id="fruit-description">Something to include in a fruit salad.</Description><Select.Root> <Select.HtmlSelect id="fruit" aria-describedby="fruit-description"> <option value="kiwi">Kiwi</option> <option value="mango">Mango</option> <option value="papaya">Papaya</option> </Select.HtmlSelect></Select.Root>Additional props
Section titled “Additional props”Select.HtmlSelect
Section titled “Select.HtmlSelect”The actual select element to be used inside Select.Root. This is a wrapper around the
HTML <select> element and should render HTML <option> elements as children.
Example usage:
<Select.HtmlSelect> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option></Select.HtmlSelect>The usage of this component largely mirrors how the <select> element would be used in React.
You can use the same familiar props, including name, defaultValue, value, onChange, etc.
accessibleWhenDisabled
Section titled “accessibleWhenDisabled”boolean | undefined (optional) Indicates whether the element should be focusable even when it is
disabled.
This is important when discoverability is a concern. For example:
A toolbar in an editor contains a set of special smart paste functions that are disabled when the clipboard is empty or when the function is not applicable to the current content of the clipboard. It could be helpful to keep the disabled buttons focusable if the ability to discover their functionality is primarily via their presence on the toolbar.
Learn more on Focusability of disabled controls.
autoFocus
Section titled “autoFocus”boolean | undefined (optional) false Automatically focuses the element upon mounting, similar to the native
autoFocus prop. This addresses an issue where the element with the native
autoFocus attribute might receive focus before React effects are
executed.
The autoFocus prop can also be used with
Focusable elements within a
Dialog component, establishing the
initial focus as the dialog opens.
Note: For this prop to work, the
focusable prop must be
set to true, if it’s not set by default.
disabled
Section titled “disabled”boolean | undefined (optional) false Determines if the element is disabled. This sets the aria-disabled
attribute accordingly, enabling support for all elements, including those
that don’t support the native disabled attribute.
This feature can be combined with the
accessibleWhenDisabled
prop to make disabled elements still accessible via keyboard.
Note: For this prop to work, the
focusable prop must be
set to true, if it’s not set by default.
render
Section titled “render”(props: P) => React.ReactNode | React.ReactElement | undefined (optional) Allows the component to be rendered as a different HTML element or React component. The value can be a React element or a function that takes in the original component props and gives back a React element with the props merged.
Check out the Composition guide for more details.
variant
Section titled “variant”"solid" | "outline" | "ghost" | undefined (optional) "solid" The variant of the HtmlSelect, i.e. solid, outline, or ghost.