Skip to content

Select

Select

A native <select> with Fluent styling: a 1px border with an accessible bottom stroke, a token chevron at the inline end (replaceable through icon) and a primary bottom border while focused. Give it a name with a Field label, aria-label or aria-labelledby. Inside a Field it picks up the label, hint, error, required (native attribute) and invalid state automatically.

size resolves from its own prop, then the surrounding Field's size, then WaveProvider inputDefaults.size, else 'medium'; appearance from its own prop, then WaveProvider inputDefaults.appearance, else 'outline'; both render as data-size and data-appearance on the <select>.

Examples

Default

export const Default: Story = {
  render: (args) => (
    <Select {...args}>
      <option value="">Select an option</option>
      <option value="a">Option A</option>
      <option value="b">Option B</option>
      <option value="c">Option C</option>
    </Select>
  ),
};

Error

Please select a value
export const Error: Story = {
  args: {
    error: 'Please select a value',
  },
  render: (args) => (
    <Select {...args}>
      <option value="">Select an option</option>
      <option value="a">Option A</option>
    </Select>
  ),
};

Disabled

export const Disabled: Story = {
  args: {
    disabled: true,
  },
  render: (args) => (
    <Select {...args}>
      <option value="">Disabled</option>
    </Select>
  ),
};

In Field

Where you live today.

export const InField: Story = {
  args: {
    'aria-label': undefined,
    defaultValue: '',
  },
  render: (args) => (
    <Field label="Country" hint="Where you live today." required>
      <Select {...args}>
        <option value="" disabled>
          Choose a country
        </option>
        <option value="no">Norway</option>
        <option value="se">Sweden</option>
      </Select>
    </Field>
  ),
};

Sizes And Appearances

export const SizesAndAppearances: Story = {
  render: (args) => (
    <SizeAppearanceGrid
      render={(size, appearance) => (
        <Select {...args} size={size} appearance={appearance} aria-label={`${size} ${appearance}`}>
          <option>Norway</option>
          <option>Sweden</option>
        </Select>
      )}
    />
  ),
};

Custom Icon

export const CustomIcon: Story = {
  render: (args) => (
    <div className="flex flex-col gap-3">
      <Select
        {...args}
        aria-label="Sort by"
        icon={
          <svg viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.5">
            <path d="M5 8l5 5 5-5" />
          </svg>
        }
      >
        <option>Name</option>
        <option>Date</option>
      </Select>
      <Select {...args} aria-label="No chevron" icon={false}>
        <option>Name</option>
        <option>Date</option>
      </Select>
    </div>
  ),
};

Controlled

Selected: a
export const Controlled: Story = {
  render: function Render(args) {
    const [value, setValue] = useState('a');
    return (
      <div className="flex flex-col gap-2">
        <Select {...args} value={value} onValueChange={setValue}>
          <option value="a">Option A</option>
          <option value="b">Option B</option>
        </Select>
        <span className="text-wave-caption-1 text-wave-muted-foreground">Selected: {value}</span>
      </div>
    );
  },
};

Props

NameTypeRequiredDefaultDescription
errorstring | booleanNo

Validation error.
- A non-empty string renders the message in a role="alert" element **after** the select (a sibling, so ref and className stay on the select) and links it through aria-describedby and aria-errormessage. Inside a Field that renders its own error, the message is not repeated.
- true only marks the select invalid (aria-invalid and the error border), as in 0.4.

The error border also shows whenever the select ends up aria-invalid="true" without this prop (an error on the surrounding Field, or your own aria-invalid). Your own aria-invalid={false} (or "false") wins over this prop: the select is reported valid and shows neither the error border nor the message.

errorMessagePropsInputErrorMessagePropsNo

Props of the error message element (id, className, …) rendered for a string error.

size'small' | 'medium' | 'large'No

Size of the field: small (24px tall), medium (32px) or large (40px). Default: the surrounding Field's size, else WaveProvider inputDefaults.size, else 'medium'. A value outside the three sizes (a number from untyped code included) renders as if size were not set. The native size attribute, the number of visible rows, is htmlSize.

htmlSizenumberNo

The native size attribute: the number of visible rows.

appearance'outline' | 'underline' | 'filled-darker' | 'filled-lighter'No

Look of the field: outline (a full border), underline (a bottom stroke only), filled-darker or filled-lighter (a fill without a visible stroke: give the field a visible label). Default: WaveProvider inputDefaults.appearance, else 'outline'.

iconSlot<'span'>Nothe drawn chevron

The chevron at the inline end (Fluent UI's icon slot). null or undefined keep the drawn chevron; false, or anything that renders nothing, draws none; content replaces it. With content a <span> wraps the <select> and the icon: the <select> still receives ref, className and the other props, and the icon is decorative (aria-hidden), carries the stable class wave-select__icon, takes no pointer events (the click reaches the select) and dims with a disabled select. The wrapper (wave-select__wrapper) is as wide as its container, so size a Select with an icon through a container, not a width class on it. The icon takes the box of its size (12px, 16px, 20px); give it an svg that fills it.

onValueChange(value: string) => voidNo

Called with the selected option's value on every change, next to the native onChange event handler (onValueChange={setCountry} instead of onChange={(e) => setCountry(e.target.value)}). Fluent UI's onChange(event, data) with data.value. With multiple it receives the first selected option's value (the select's value); read event.currentTarget.selectedOptions in onChange for all of them.

refReact.Ref<HTMLSelectElement>No

Ref to the <select> element.

Any other prop is passed to the element it renders (HTMLSelectElement).

Stable class names

PartClass
rootwave-select
errorMessagewave-select__error-message
wrapperwave-select__wrapper
iconwave-select__icon