Search docs

Select

Displays a list of options for the user to pick from—triggered by a button.

Select follows the Select-Only Combobox WAI-ARIA design pattern.

Use Field.Select (Field) when a native <select> is enough, Select for a custom-styled dropdown without typing, and Combobox when users need to type to filter options.

Apple
Banana
Blueberry
Cherry
Grape
Lemon
Orange
Peach

Selected: none

import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Select } from '@leve-ui/select';
import { LuCheck, LuChevronDown } from '@qwikest/icons/lucide';
import styles from './default.css?inline';

const FRUITS = [
  { value: 'apple', label: 'Apple' },
  { value: 'banana', label: 'Banana' },
  { value: 'blueberry', label: 'Blueberry' },
  { value: 'cherry', label: 'Cherry' },
  { value: 'grape', label: 'Grape' },
  { value: 'lemon', label: 'Lemon', disabled: true },
  { value: 'orange', label: 'Orange' },
  { value: 'peach', label: 'Peach' },
];

export default component$(() => {
  useStyles$(styles);
  const value = useSignal<string | null>(null);

  return (
    <div class="select-default">
      <Select.Root bind:value={value} class="select-default-root">
        <Select.Label class="select-default-label">Fruit</Select.Label>
        <Select.Trigger class="select-default-trigger">
          <Select.Value placeholder="Select a fruit" class="select-default-value" />
          <LuChevronDown aria-hidden="true" class="select-default-icon" />
        </Select.Trigger>
        <Select.Content sideOffset={4} class="select-default-content">
          <Select.List>
            {FRUITS.map((fruit) => (
              <Select.Item
                key={fruit.value}
                value={fruit.value}
                disabled={fruit.disabled}
                class="select-default-item"
              >
                <Select.ItemText>{fruit.label}</Select.ItemText>
                <Select.ItemIndicator class="select-default-indicator">
                  <LuCheck aria-hidden="true" class="select-default-icon" />
                </Select.ItemIndicator>
              </Select.Item>
            ))}
          </Select.List>
        </Select.Content>
      </Select.Root>
      <p class="select-default-status">Selected: {value.value ?? 'none'}</p>
    </div>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/select

Anatomy#

import { Select } from '@leve-ui/select'; // or '@leve-ui/core'

<Select.Root>
  <Select.Label />
  <Select.Trigger>
    <Select.Value />
  </Select.Trigger>
  <Select.HiddenInput />
  <Select.Content>
    <Select.List>
      <Select.Item>
        <Select.ItemText />
        <Select.ItemIndicator />
      </Select.Item>
      <Select.Group>
        <Select.GroupLabel />
        <Select.Item />
      </Select.Group>
    </Select.List>
  </Select.Content>
</Select.Root>
PartElementDescription
Select.Root<div>Wraps the parts and holds the selected value and open state.
Select.Label<label>The label for the trigger and the accessible name of the listbox.
Select.Trigger<button>Button with role="combobox" that toggles the listbox. Focus stays here.
Select.Value<span>Displays the selected option's text or a placeholder.
Select.HiddenInput<input>Optional. Submits the selected value with a native <form>.
Select.Content<div>The popup, a popover="manual" element in the top layer.
Select.List<div>The listbox (role="listbox").
Select.Item<div>An option (role="option").
Select.ItemText<span>The text displayed in Select.Value when the option is selected.
Select.ItemIndicator<span>The check mark of the selected option, hidden otherwise.
Select.Group<div>A group of options, named by its GroupLabel.
Select.GroupLabel<div>The name of a group. Not selectable.

Examples#

Groups and Looping#

Select.Group and Select.GroupLabel organize options into labeled groups. With loop, arrow keys wrap between the first and last options.

Americas
New York
Chicago
Los Angeles
Europe
London
Paris
Berlin
Asia
Tokyo
Seoul
Singapore

Disabled#

disabled on Select.Root prevents opening and disables Select.Trigger and Select.HiddenInput.

Free
Starter
Pro

Field and Form#

Inside a Field, Select.Trigger receives the Field's id, label, description, error message, invalid, disabled, and required states. Add Select.HiddenInput to participate in native <form> submission and reset.

Japan
United States
United Kingdom
Used for shipping and tax calculation.

Controlled#

Use bind:value to read and update the selected value with a signal. Setting it to null restores the placeholder.

Apple
Banana
Orange

Current value: banana

API Reference#

Root#

PropDefaultType
ids–{ label?: string; trigger?: string; list?: string }

Overrides the element IDs of the parts. Inside a Field, the Field's IDs are used for the label and trigger.

defaultValuenullstring | null

The value of the selected item initially (uncontrolled).

bind:value–Signal<string | null>

A signal with the value of the selected item (controlled). null when nothing is selected.

onValueChange$–QRL<(value: string | null) => void>

Called when the selected value changes.

defaultOpenfalseboolean

Whether the listbox is open initially (uncontrolled).

bind:open–Signal<boolean>

A signal with the open state of the listbox (controlled).

onOpenChange$–QRL<(open: boolean) => void>

Called when the listbox opens or closes.

disabledfalseboolean

Whether the select is disabled. Inside a Field or Fieldset, inherited disabled also applies.

requiredfalseboolean

Whether a value is required in a form. Inside a Field, the Field's required also applies.

loopfalseboolean

Whether ArrowDown on the last item moves to the first one, and ArrowUp on the first to the last.

Also accepts all <div> attributes.

Data attributeValue
data-leve-selectAlways present
data-state"open" | "closed"
data-disabledPresent when disabled

Label#

No props of its own. Accepts all <label> attributes.

Data attributeValue
data-leve-select-labelAlways present
data-disabledPresent when disabled

Trigger#

PropDefaultType
invalidfalseboolean

Whether the select value is invalid. Inside a Field, the Field's invalid also applies.

Also accepts all <button> attributes.

Data attributeValue
data-leve-select-triggerAlways present
data-state"open" | "closed"
data-placeholderPresent when no option is selected
data-disabledPresent when disabled
data-invalidPresent when invalid

Value#

PropDefaultType
placeholder–string

Text displayed when no item is selected.

Also accepts all <span> attributes.

Data attributeValue
data-leve-select-valueAlways present
data-placeholderPresent when no option is selected

When defaultValue or bind:value has an initial value, Select.Value resolves the matching option's text from the DOM on the client. Pass fallback text as children (for example, <Select.Value>Banana</Select.Value>) so the initial label renders during SSR before the client resolves it.

HiddenInput#

PropDefaultType
form–string

The id of the form element to associate the input with.

Also accepts all <input> attributes.

Data attributeValue
data-leve-select-hidden-inputAlways present

It is positioned absolutely, so give Select.Root position: relative.

Content#

PropDefaultType
side'bottom''top' | 'right' | 'bottom' | 'left'

The side of the Trigger to place the listbox on. It flips when there is no room.

align'start''start' | 'center' | 'end'

The alignment along that side.

sideOffset0number

The distance from the Trigger in px.

alignOffset0number

The offset along the side in px.

avoidCollisionstrueboolean

Whether to flip and shift the listbox to keep it in the viewport.

collisionPadding0number

The padding from the viewport edges when avoiding collisions, in px.

Also accepts all <div> attributes.

Data attributeValue
data-leve-select-contentAlways present
data-state"open" | "closed"
data-sideThe final side after flipping
data-align"start" | "center" | "end"
CSS variableValue
--leve-select-anchor-widthThe width of the Trigger, for example to match the listbox width
--leve-select-anchor-heightThe height of the Trigger
--leve-select-available-widthThe width available in the viewport
--leve-select-available-heightThe height available in the viewport, for example for max-height

List#

No props of its own. Accepts all <div> attributes.

Data attributeValue
data-leve-select-listAlways present

Item#

PropDefaultType
value (required)–string

The value of the item. Must be unique within the select.

disabledfalseboolean

Whether the item cannot be selected. Arrow keys and typeahead skip it.

textValue–string

The display and typeahead text for the item, when it differs from ItemText or its text content.

Also accepts all <div> attributes.

Data attributeValue
data-leve-select-itemAlways present
data-valueThe value
data-state"checked" | "unchecked"
data-highlightedPresent on the highlighted option
data-disabledPresent when disabled
data-text-valueThe textValue, when set

Focus stays on the trigger, so style the highlighted option with [data-highlighted], not :focus.

ItemText#

No props of its own. Accepts all <span> attributes.

Data attributeValue
data-leve-select-item-textAlways present

ItemIndicator#

No props of its own. Accepts all <span> attributes.

Data attributeValue
data-leve-select-item-indicatorAlways present
data-state"checked" | "unchecked"

It has the hidden attribute while the option is unselected. If you set display on it, hide it again with [hidden] { display: none; }.

Group#

No props of its own. Accepts all <div> attributes.

Data attributeValue
data-leve-select-groupAlways present

GroupLabel#

No props of its own. Accepts all <div> attributes.

Data attributeValue
data-leve-select-group-labelAlways present

Accessibility#

Complies with the Select-Only Combobox WAI-ARIA design pattern.

  • Select.Trigger renders <button type="button" role="combobox"> with aria-haspopup="listbox", aria-expanded, aria-controls, and aria-labelledby. Focus stays on the trigger, and aria-activedescendant points to the highlighted option while open.
  • Select.List renders role="listbox", named by the label. Options render role="option" with aria-selected; disabled options render aria-disabled="true" and are skipped by arrow keys and typeahead.
  • Select.Group renders role="group", named by its Select.GroupLabel. Select.ItemIndicator is hidden from assistive technologies with aria-hidden="true", since aria-selected conveys the state.
  • Inside a Field, the trigger receives the Field's id, label, description, error message, invalid, disabled, and required states.

Keyboard Interactions#

KeyDescription
Enter / SpaceWhen closed, opens the listbox and highlights the selected option (or the first enabled option). When open, selects the highlighted option and closes.
ArrowDownWhen closed, opens the listbox and highlights the selected option (or the first enabled option). When open, highlights the next enabled option.
ArrowUpWhen closed, opens the listbox and highlights the selected option (or the last enabled option). When open, highlights the previous enabled option (or closes with Alt + ArrowUp).
HomeOpens the listbox if closed and highlights the first enabled option.
EndOpens the listbox if closed and highlights the last enabled option.
EscapeCloses the listbox without changing the value and keeps focus on the trigger.
TabCloses the listbox and moves focus to the next focusable element.
CharactersTypeahead: jumps to the matching enabled option (and opens the listbox if closed).