Select
An exposed dropdown menu: a field that opens a menu of options. One or several choices, sections, a search for long lists, a sheet on phones.
import { Select, SelectItem, SelectSection, OptionPopover } from '@windmorph/react';Props
Select 53 props
Shown in the field when nothing is chosen. With a
label, it appears once the label floats (on focus), as inTextField.The trigger button's id, for a
<label for>or an error summary's link.The container style, as
TextField's: a filled surface or an outline.Web density,
0to-3: each step takes 4px off the field (56px at 0, 44px at -3) and off its menu's options (44px at 0, 32px at -3). Left out, it takes the density of the nearestThemeProviderorThemeScope. M3 asks for density to be the reader's choice rather than a default, so prefer setting it there, from a setting.The field's label. Give
aria-labelinstead when there's no visible label.Helper text below the field. Replaced visually by the error when invalid, and shown in the error colour while the field is invalid.
Marks the field invalid (in addition to
validateandrequired).A choice is required: adds the
*to the label and validates on submit.Read as
invalidwhen that's left out, for a form library that sets the attribute. The trigger is a button, which ARIA doesn't let carryaria-invalid, so the state reaches assistive technology as the field's error text, its description.Read as
requiredwhen that's left out, for a form library that sets the attribute: the label's*, in the trigger's name (a button can't carryaria-required).Disables the field: it can't be focused or opened.
The choice can be seen but not changed: the menu doesn't open and the keyboard doesn't change it. The root gets
data-readonly; say so in the supporting text (M3).Decorative icon at the start, in a 48px box.
The icon shown before the arrow while the field is invalid (M3 strongly recommends one). Defaults to Material Symbols
error, named bylabels.error;falseturns it off.Whether the menu is open (controlled); with
defaultOpenandonOpenChange.Whether choosing an option closes the menu.
With
selectionMode="multiple", the most options that can be chosen; the rest show as disabled until one is removed.menu(default) opens an M3 menu under the field on every window, as Compose's exposed dropdown menu does;sheetalways opens a bottom sheet;autoopens a sheet on compact windows and a menu on larger ones, for long lists.A search field at the top of the menu or sheet that filters the options as you type, for long lists (pair it with
presentation="auto"). The search takes focus in the menu; a sheet shows the list first, so the keyboard doesn't cover it.With
searchable: whether an option matches the search. Defaults to a match anywhere in its text, ignoring case and accents ("thai" finds "Thailand"). The option'skeylets it match on more than its text, e.g. a country's ISO code.With
searchable: the typed text (controlled); cleared when the list closes.With
searchable: the initial typed text, when uncontrolled.What the field shows for the chosen option(s), e.g. a dialling code or a flag, instead of their text. Screen readers still hear the options' text.
Shows a loading indicator in the list, e.g. while options are fetched. The indicator's code loads when it first shows, and ahead of that when the field is hovered or focused while this prop is set at all, so pass
loading={false}(rather than leaving it out) on a field that loads options.Ref to the root
<div>element. UsetriggerReffor the field's button.Ref to the field's button.
Events
With
searchable: called as the search changes. Given it, the app filtersitemsitself (e.g. on a server, withloadingmeanwhile) and the built-in filter is off.
Text
Accessible name when there's no visible label.
Words the Select shows or announces, for other languages. A
LabelsProvidersets them for the whole app.Shown in an empty list.
The loading indicator's name.
For more chosen options than fit:
+{count}.With
searchable: the search field's placeholder and name.With
searchable: shown when no option matches the search.The error icon's name (M3: "Error").
Classes for the root element, merged with
classNames.root; consumer classes win.Classes for each part, by slot.
The text showing the chosen option(s) or the placeholder.
With
searchable: the search field.The bottom sheet the options open in (
presentation="sheet", or"auto"on compact windows): the sheet's surface, as itsclassNames.panel.The root element, merged with
className.The filled or outlined container around the label, value and icons.
The floating label.
The row holding the field's value (the button, or the chips and input).
The leading icon's 48px box.
The trailing box holding the arrow (and the error icon).
The helper text below the field.
The error message below the field.
The built-in error icon.
The outlined field's border (a
<fieldset>, notched for the floated label).The filled field's active indicator, the line along the container's bottom.
The list's surface.
Each option.
Each option's leading icon, or the check shown on a chosen option.
Each option's
descriptionline.Each option's
trailingtext.Each section's heading.
The divider between sections.
The text shown when no option matches.
Inline styles for the root element.
Whether single or multiple selection is enabled.
Sets the default open state of the menu.
Method that is called when the open state of the menu changes.
The contents of the collection.
Item objects in the collection.
The keys of the items that can't be selected or pressed. They stay focusable, so keyboard and screen reader users still find them.
The current value (controlled).
The default value (uncontrolled).
Handler that is called when the value changes.
Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.
A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if
validationBehavior="native". For realtime validation, use theinvalidprop instead.An error message for the field.
Whether the element should receive focus on render.
Handler that is called when the element receives focus.
Handler that is called when the element loses focus.
Handler that is called when the element's focus status changes.
Handler that is called when a key is pressed.
Handler that is called when a key is released.
The name of the input, used when submitting an HTML form.
Describes the type of autocomplete functionality the input should provide if any. See MDN.
The
<form>element to associate the input with. The value of this attribute must be the id of a<form>in the same document. See MDN.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
SelectItem 6 props
The label.
Plain-text label for typeahead, filtering and the field, when
childrenisn't a string.Icon (or avatar, flag…) before the label.
Second line of text.
Short text at the end, e.g. a dialling code or a count.
SelectSection 2 props
OptionPopover 8 props
The open state the popover follows (from React Stately's
useOverlayTriggerState).The field the popover is placed under and matches the width of.
Ref to the popover's surface.
Keeps the page interactive while open (no underlay, focus stays in the field), as an editable field's menu needs.
The least width, when the field is narrower (a searchable menu needs room to type).
placementtype"bottom" | "bottom-start" | "bottom-end" | "top" | "top-start" | "top-end"default"bottom-start"The side of the field it opens on, then optionally the edge it lines up with:
topfor a field near the bottom of the window (a composer's suggestions), whose list should rise above it. Either way it flips to the other side when there's no room for it, and reveals from the edge next to the field.startandendfollow the field's laid-out direction.The field's own density, which its menu takes; left out, the theme's.
Spec status
Built to the M3 Expressive select spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| Vertical menu | Built | Variant · Basic |
| Color: standard | Built | Configuration · Basic |
| Layout: standard | Built | Configuration · Basic |
| Layout: grouped | Built | Configuration · Variants, Searchable |
| Filled and outlined fields | Built | Configuration · Variants |
| A menu opening from a text field | Built | Use case · Basic |
| Focus when the menu opens | Differs | The chosen option, or else the first one, takes focus (the WAI-ARIA listbox pattern); M3's menu page says the first item, written for action menus. |
| Density | Extension | M3 gives text fields and menus web density; density (0 to -3, or the theme's) takes 4px a step off the field and off its options. |
presentation="sheet" and "auto" | Extension | Opens the options in a bottom sheet, always or below 600px; the default menu is M3's dropdown on every window. |
searchable | Extension | A search at the top of the menu or sheet that filters as you type, built from the search bar's field at 48px. |
| Multiple selection | Extension | selectionMode="multiple" with maxSelections; the field lists the chosen options. |
renderValue and loading | Extension | What the field shows for the chosen option, and a loading indicator in the list. |
| Color: vibrant | Not built | The options list always uses the standard menu colours; the vibrant style is on Menu (variant="vibrant") for action menus. |
Vertical menu
BuiltVariant · Basic
Color: standard
BuiltConfiguration · Basic
Layout: standard
BuiltConfiguration · Basic
Layout: grouped
BuiltConfiguration · Variants, Searchable
Filled and outlined fields
BuiltConfiguration · Variants
A menu opening from a text field
BuiltUse case · Basic
Focus when the menu opens
DiffersThe chosen option, or else the first one, takes focus (the WAI-ARIA listbox pattern); M3's menu page says the first item, written for action menus.
Density
ExtensionM3 gives text fields and menus web density;
density(0 to -3, or the theme's) takes 4px a step off the field and off its options.
Extensionpresentation="sheet"and"auto"Opens the options in a bottom sheet, always or below 600px; the default
menuis M3's dropdown on every window.
ExtensionsearchableA search at the top of the menu or sheet that filters as you type, built from the search bar's field at 48px.
Multiple selection
ExtensionselectionMode="multiple"withmaxSelections; the field lists the chosen options.
ExtensionrenderValueandloadingWhat the field shows for the chosen option, and a loading indicator in the list.
Color: vibrant
Not builtThe options list always uses the standard menu colours; the vibrant style is on
Menu(variant="vibrant") for action menus.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
Select: 38.7 kBSelectItem,SelectSection,OptionPopover: 22.0 kB
M3 Expressive specs
- Shape
rounded-corner-extra-small- Variants
filled, outlined- Elevation
level2
Building blocks
OptionPopover is the popover the options open in, exported for building a field of your own on top: it anchors to a trigger, is at least as wide as it, opens below it (or above, with placement="top", for a field near the bottom of the window), flips to the other side when there's no room, and opens and closes with the menu's motion, growing from the edge next to the trigger. Pass it React Stately's overlay state and the trigger's ref; nonModal keeps an input beside it usable, as Autocomplete does.
Differences from Compose
- The field is the library's Text field (filled by default, or outlined) and the list is its Menu, so neither can drift: Compose's
ExposedDropdownMenuBoxwith aPrimaryNotEditableanchor. The menu is as wide as the field, and the arrow turns over while it's open. It opens as the Menu does, expanding from the field's edge, rather than Compose's 80% scale, which the M3 motion spec avoids. presentationadds what Compose leaves to apps:"sheet"opens the options in a bottom sheet, and"auto"does so on compact windows only. The default,"menu", is M3's baseline on every window.- Multiple selection and
maxSelections, which Compose's exposed dropdown doesn't have. searchable: M3 doesn't define a search inside a menu, so it's built from M3 parts. The search is the M3 search bar's field at 48px, M3's minimum touch target, rather than the bar's 56px, so it doesn't dominate the 44px rows; it filters ignoring case and accents, andfilteroronSearchChange(for server results) replace that. A searchable menu is at least 280px wide, room to type.