Select

Single selects get a chevron drawn from --icon-chevron. Multiple and sized selects keep the native list, with no icon.

ClassDoes what
selectFull-width select with a chevron
select-errorError color, for when aria-invalid is not available

Basic

<label class="label">
  Environment
  <select class="select">
    <option>Development</option>
    <option>Staging</option>
    <option>Production</option>
  </select>
</label>

Multiple

<select class="select" multiple size="3">
  <option>One</option>
  <option>Two</option>
  <option>Three</option>
</select>

With Kobalte

alpha The class names and states here are stable. The look is not: these styles can change in a minor release, without a major version bump.

The native <select> above is settled. What follows is not: the listbox styling and .menu-selected are new.

Kobalte's Select is a button plus a listbox, not a native <select>. The Kobalte layer gives the trigger the field styling above and styles the listbox and its options. Select.Content, the panel around the listbox, has no role of its own, so it takes .dropdown-content by hand.

<select class="select">
  <option>Development</option>
  <option>Production</option>
</select>

Leave out Select.Icon: the field draws its own chevron, the same one the native select gets.

On the class-based build

Put the classes on the parts yourself. The rows follow Kobalte's state without any extra classes: a highlighted row matches data-highlighted and a selected one aria-selected, which is also what Radix and Ark set. For a compact trigger, such as a version switcher, use a button and keep Select.Icon; for a form field, use .select and leave it out, since the field draws its own chevron.

<Select
  options={versions()}
  optionValue="id"
  optionTextValue="label"
  value={current()}
  onChange={setCurrent}
  itemComponent={props => (
    <Select.Item item={props.item} class="menu-item">
      <Select.ItemLabel>{props.item.rawValue.label}</Select.ItemLabel>
    </Select.Item>
  )}
>
  <Select.Trigger class="btn btn-secondary" aria-label="Version">
    <Select.Value>{state => state.selectedOption().label}</Select.Value>
    <Select.Icon>▾</Select.Icon>
  </Select.Trigger>
  <Select.Portal>
    <Select.Content class="dropdown-content">
      <Select.Listbox class="menu" />
    </Select.Content>
  </Select.Portal>
</Select>

Disabled

<select class="select" disabled>
  <option>Production</option>
</select>

The trigger is a form field, so it carries the same bottom margin as an .input. That margin is overridden in this demo because the listbox sits inline here; in an app the content is portaled and positioned by Kobalte's popper, which sets the gap with its gutter prop.

data-selected marks the chosen option and data-highlighted the one under the pointer or caret, so they get different treatments: .menu-selected and .menu-active.

Composition

Common ways to put this together with other components. The general rules are on Composition.

Sort beside search

A search field that takes the width, and a sort select beside it.

Same markup in both builds
<div class="field-row" style="flex-wrap: wrap">
  <label class="label" style="flex: 1 1 16rem">
    <p>Search</p>
    <input class="input" type="search" />
  </label>
  <label class="label" style="flex: 0 1 12rem">
    <p>Sort</p>
    <select class="select">
      <option>Newest</option>
      <option>Oldest</option>
      <option>A to Z</option>
    </select>
  </label>
</div>