Skip to content

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

By name or description, across the 69 props below

Select 53 props

  • placeholdertype string

    Shown in the field when nothing is chosen. With a label, it appears once the label floats (on focus), as in TextField.

  • idtype string

    The trigger button's id, for a <label for> or an error summary's link.

  • varianttype "filled" | "outlined"default "filled"

    The container style, as TextField's: a filled surface or an outline.

  • densitytype 0 | -1 | -2 | -3default 0

    Web density, 0 to -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 nearest ThemeProvider or ThemeScope. M3 asks for density to be the reader's choice rather than a default, so prefer setting it there, from a setting.

  • labeltype ReactNode

    The field's label. Give aria-label instead when there's no visible label.

  • supportingTexttype ReactNode

    Helper text below the field. Replaced visually by the error when invalid, and shown in the error colour while the field is invalid.

  • invalidtype boolean

    Marks the field invalid (in addition to validate and required).

  • requiredtype boolean

    A choice is required: adds the * to the label and validates on submit.

  • aria-invalidtype boolean | "true" | "false" | "grammar" | "spelling"

    Read as invalid when that's left out, for a form library that sets the attribute. The trigger is a button, which ARIA doesn't let carry aria-invalid, so the state reaches assistive technology as the field's error text, its description.

  • aria-requiredtype Booleanish

    Read as required when that's left out, for a form library that sets the attribute: the label's *, in the trigger's name (a button can't carry aria-required).

  • disabledtype booleandefault false

    Disables the field: it can't be focused or opened.

  • readOnlytype booleandefault false

    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).

  • leadingIcontype ReactNode

    Decorative icon at the start, in a 48px box.

  • errorIcontype ReactNode

    The icon shown before the arrow while the field is invalid (M3 strongly recommends one). Defaults to Material Symbols error, named by labels.error; false turns it off.

  • opentype boolean

    Whether the menu is open (controlled); with defaultOpen and onOpenChange.

  • closeOnSelecttype booleandefault true for a single choice, false with selectionMode="multiple"

    Whether choosing an option closes the menu.

  • maxSelectionstype number

    With selectionMode="multiple", the most options that can be chosen; the rest show as disabled until one is removed.

  • presentationtype "menu" | "sheet" | "auto"default "menu"

    menu (default) opens an M3 menu under the field on every window, as Compose's exposed dropdown menu does; sheet always opens a bottom sheet; auto opens a sheet on compact windows and a menu on larger ones, for long lists.

  • searchabletype booleandefault false

    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.

  • filtertype ((textValue: string, search: string, key: Key) => boolean)

    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's key lets it match on more than its text, e.g. a country's ISO code.

  • searchValuetype string

    With searchable: the typed text (controlled); cleared when the list closes.

  • defaultSearchValuetype stringdefault ""

    With searchable: the initial typed text, when uncontrolled.

  • renderValuetype ((selected: SelectedOption<T>[]) => ReactNode)

    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.

  • loadingtype boolean

    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.

  • reftype Ref<HTMLDivElement>

    Ref to the root <div> element. Use triggerRef for the field's button.

  • triggerReftype Ref<HTMLButtonElement>

    Ref to the field's button.

Events

  • onSearchChangetype ((search: string) => void)

    With searchable: called as the search changes. Given it, the app filters items itself (e.g. on a server, with loading meanwhile) and the built-in filter is off.

Text

  • aria-labeltype string

    Accessible name when there's no visible label.

  • labelstype Partial<SelectLabels>

    Words the Select shows or announces, for other languages. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

SelectItem 6 props

  • childrentype ReactNodeRequired

    The label.

  • textValuetype string

    Plain-text label for typeahead, filtering and the field, when children isn't a string.

  • leadingIcontype ReactNode

    Icon (or avatar, flag…) before the label.

  • descriptiontype ReactNode

    Second line of text.

  • trailingtype ReactNode

    Short text at the end, e.g. a dialling code or a count.

Text

  • aria-labeltype string

    Accessible name when the label isn't plain text.

SelectSection 2 props

  • titletype ReactNode

    Heading shown above the options.

Text

  • aria-labeltype string

    Accessible name for the group when it has no title.

OptionPopover 8 props

  • statetype OverlayTriggerStateRequired

    The open state the popover follows (from React Stately's useOverlayTriggerState).

  • triggerReftype RefObject<HTMLElement | null>Required

    The field the popover is placed under and matches the width of.

  • popoverReftype RefObject<HTMLDivElement | null>Required

    Ref to the popover's surface.

  • nonModaltype booleandefault false

    Keeps the page interactive while open (no underlay, focus stays in the field), as an editable field's menu needs.

  • minWidthtype numberdefault 0

    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: top for 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. start and end follow the field's laid-out direction.

  • densitytype 0 | -1 | -2 | -3

    The field's own density, which its menu takes; left out, the theme's.

Events

  • onPressOutsidetype (() => void)

    A press outside the menu and the field closes it (modal menus only).

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.

  • 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.

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 kB
  • SelectItem, 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 ExposedDropdownMenuBox with a PrimaryNotEditable anchor. 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.
  • presentation adds 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, and filter or onSearchChange (for server results) replace that. A searchable menu is at least 280px wide, room to type.