Inputs
Select
Status
Value: draft
Collections
When to use
- The values are known in advance: a category, a status, a collection, a set of filters.
- You need search within a long but still closed list.
- You need one or several selected items with a type-safe value shape.
When not to use
- If the user may create a new value, use
Combobox. - If you need checkboxes with complex markup that differs from one to the next, use
CheckboxGroup. - If you need exactly one mode, always selected, use
Segmented.
Minimal example
<Select items={[{ id: "draft", label: "Draft" }]} value={status} onChange={setStatus} placeholder="Status" clearable />
<Select multiple items={tags} value={tagIds} onChange={setTagIds} searchable countLabel={(n) => `Selected: ${n}`} />Public API
- An item must have
idandlabel;keywords,meta,renderMediaand domain fields are optional. - Without
multiple:value?: SelectId | null,onChange(id | null); withmultiple: true:value?: SelectId[],onChange(ids). Clearing producesnullor[]respectively. searchableis false by default;clearable,highlightSelected, placeholders,icon,triggerClassName,contentClassNameconfigure the presentation.disableddisables the whole field: the trigger cannot be focused, the panel does not open (and an open one closes), the clear button disappears, the pill is dimmed. Behavior and look are as withButtonandTextControl.aria-label(oraria-labelledby, a reference to a label that is already rendered) sets the field's name. The name is combined with the trigger content and does not replace it: the field is announced as "Icon, Circle, button". If both are set,aria-labelledbywins.missingLabellabels a value for which no item was found initems: this happens while the list is loading and when the record was deleted. By default the key itself is shown — it is more honest than a placeholder if it is human-readable; for machine identifiers (UUIDs) set the label yourself.- For a wide form the label limit can be lifted:
triggerClassName="[--select-label-max:none]". - Anything you put in the trigger's text row must fit in 20 px. The trigger row is a
leading-5line box, and the control's height depends on it: a filter pill is 36 px (the same as aButtonof sizemd), and a trigger in a form withpy-2.5padding is 42 px (the same asTextControl,NumberInput,SearchControlandDateRangePicker). A taller child stretches the trigger and throws it out of line with the fields next to it. That is whyrenderMedia(item, px)receives the side of the square as a number, 20 in the trigger and 28 in the list, and you should draw exactly that. This does not apply to theiconandtrailingslots of the input fields: they sit beside the field rather than in its text row. - A custom font size in
triggerClassNamekeeps the height only if it is a step of the type scale: every step sets its own line box. An arbitrarytext-[15px]displaces thetext-[13px] leading-5pair as a whole, and the height is again derived from the1.5multiplier.
Accessibility and keyboard
- The hint and error of
FormFieldare announced together with the field. The description arrives through context, andaria-describedbyis set on the trigger; the value set by the consumer is not replaced but merged with it. Before version 3.0.0 the components built on react-aria did not pick up the form description — it was on the screen but did not reach the screen reader (ADR-0031). - The trigger reports
aria-haspopup="listbox"and the expanded state; clearing is a separate button. - The field name in a form is set by
aria-labeloraria-labelledby, not by theFormFieldlabel. A composite control does not accept anid, so there is nothing forhtmlForto bind to: without an explicit name the screen reader announces only the trigger content — "No icon, button" — and two such fields side by side cannot be told apart by ear. In a filter bar no name is needed: there the placeholder is the name of the filter. The name fromaria-labelgoes into a hidden node and is read together with the value; a plainaria-labelon the button would win over the content, and the field would stop reporting what is selected in it (the same technique is inTreeSelect). - In the list, the arrow keys, Home/End, Enter/Space and Escape work. In searchable mode the arrow keys move focus between the search and the list.
- Sources:
src/components/inputs/Select.tsx,src/components/inputs/Select.stories.tsx,tests/select.test.tsx.
TypeScript types
SelectProps
Prop
Type