---
id: "packages/active-ui/select"
title: "Select"
description: "One choice from a list in a popup, with the label of the chosen item in the trigger, groups and disabled items."
url: "/packages/active-ui/select"
locale: "en"
revision: "bca98e35ca3cff57"
---

# Select

A select shows the current choice in a compact trigger and opens a list to change it. Use it for a
handful to a few dozen options that need no search; with more options, or when the reader knows
what to type, use a [combobox](/packages/active-ui/combobox). When the options must be compared
side by side, a [radio group](/packages/active-ui/radio-group) shows them all. On a phone, a
[native select](/packages/active-ui/native-select) opens the system picker.

**Example: A value, groups and the small size**

Client: Runs entirely in your browser. Source: `examples/ui/select.tsx`.

```tsx
// apps/docs/examples/ui/select.tsx
'use client';

import {useState} from 'react';

import {
  Field,
  FieldDescription,
  FieldLabel,
} from '@workspace/active-ui/components/primitives/field';
import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectLabel,
  SelectSeparator,
  SelectTrigger,
  SelectValue,
} from '@workspace/active-ui/components/primitives/select';

/**
 * One choice from a list in a popup. The trigger shows the label of the
 * chosen item, not its value: `Select` derives the labels from its items.
 * Items can be grouped under labels and disabled.
 */
export default function SelectExample() {
  const [frequency, setFrequency] = useState<string | null>('monthly');
  return (
    <div className="grid w-full max-w-xs gap-6">
      <Field>
        <FieldLabel id="select-frequency-label">Statement frequency</FieldLabel>
        <Select
          value={frequency}
          onValueChange={(value) => setFrequency(value)}
        >
          <SelectTrigger
            className="w-full"
            aria-labelledby="select-frequency-label"
          >
            <SelectValue />
          </SelectTrigger>
          <SelectContent>
            <SelectItem value="monthly">Every month</SelectItem>
            <SelectItem value="quarterly">Every quarter</SelectItem>
            <SelectItem value="yearly">Every year</SelectItem>
            <SelectItem value="never" disabled>
              Never (required by law)
            </SelectItem>
          </SelectContent>
        </Select>
        <FieldDescription>Value: {frequency}</FieldDescription>
      </Field>

      <Field>
        <FieldLabel id="select-zone-label">Time zone</FieldLabel>
        <Select>
          <SelectTrigger className="w-full" aria-labelledby="select-zone-label">
            <SelectValue placeholder="Choose a time zone" />
          </SelectTrigger>
          <SelectContent>
            <SelectGroup>
              <SelectLabel>Europe</SelectLabel>
              <SelectItem value="Europe/Amsterdam">Amsterdam</SelectItem>
              <SelectItem value="Europe/London">London</SelectItem>
            </SelectGroup>
            <SelectSeparator />
            <SelectGroup>
              <SelectLabel>America</SelectLabel>
              <SelectItem value="America/New_York">New York</SelectItem>
              <SelectItem value="America/Chicago">Chicago</SelectItem>
            </SelectGroup>
          </SelectContent>
        </Select>
      </Field>

      <Field>
        <FieldLabel id="select-size-label">Rows per page</FieldLabel>
        <Select defaultValue="25">
          <SelectTrigger size="sm" aria-labelledby="select-size-label">
            <SelectValue />
          </SelectTrigger>
          <SelectContent>
            <SelectItem value="10">10</SelectItem>
            <SelectItem value="25">25</SelectItem>
            <SelectItem value="50">50</SelectItem>
          </SelectContent>
        </Select>
      </Field>
    </div>
  );
}
```

## Usage

```tsx
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from '@workspace/active-ui/components/primitives/select';

<Select value={frequency} onValueChange={setFrequency}>
  <SelectTrigger aria-labelledby="frequency-label">
    <SelectValue placeholder="Choose" />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="monthly">Every month</SelectItem>
    <SelectItem value="yearly">Every year</SelectItem>
  </SelectContent>
</Select>;
```

## The label in the trigger

Base UI's select stores a **value** and shows it in `SelectValue`; on its own that would show
`monthly` instead of "Every month". This package's `Select` reads the label of each `SelectItem`
from its children and hands Base UI the pairs (`items`), so the trigger shows the label.

- This works for string and number values written directly as `SelectItem` children of the
  select, at any depth of plain JSX (groups included).
- Items rendered by a component of your own are invisible to that walk: pass `items` yourself, as
  an **array** of `{value, label}`, or the trigger shows the raw value.
- For object values, give each object a `label`, or pass `itemToStringLabel`.

## Anatomy

- `Select`: the value. `value` and `onValueChange` (controlled), or `defaultValue`; `multiple` for
  several values; `name` for a native form.
- `SelectTrigger`: the button that opens the list. `size`: `default` or `sm`.
- `SelectValue`: the label of the chosen item, or the `placeholder`.
- `SelectContent`: the popup. By default it opens over the trigger with the chosen item aligned to
  it (`alignItemWithTrigger`); set it to `false` to open below.
- `SelectItem`, `SelectGroup` with `SelectLabel`, `SelectSeparator`.

## What your application provides

- A label for the trigger: `aria-labelledby` pointing at a `FieldLabel`, or `aria-label`.
- The options and their labels; the value, when controlled.
- A width: the trigger is as wide as its content (`w-fit`); give it `w-full` in a form.

## Accessibility and keyboard

- The trigger opens the list with `Enter`, `Space` or the arrow keys; typing a letter jumps to the
  next item that starts with it.
- In the list, the arrow keys move, `Enter` chooses and closes, `Escape` closes without a change,
  and the focus returns to the trigger.
- A disabled item is skipped.

## API

### Select

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `actionsRef` | `RefObject<SelectRootActions \| null>` | no | A ref to imperative actions. - `unmount`: Ends the closing phase of the select after an externally controlled closing animation finishes. Call `preventUnmountOnClose()` in `onOpenChange` first, otherwise the select completes closing on its own. Whether it leaves the DOM is decided by `keepMounted` on the portal. - `close`: Closes the select imperatively when called. |
| `autoComplete` | `string` | no | Provides a hint to the browser for autofill. |
| `children` | `ReactNode` | no |  |
| `defaultOpen` | `boolean` | no | Whether the select popup is initially open.  To render a controlled select popup, use the `open` prop instead. |
| `defaultValue` | `SelectInputValue<Value, Multiple> \| null` | no | The uncontrolled value of the select when it's initially rendered.  To render a controlled select, use the `value` prop instead. |
| `disabled` | `boolean` | no | Whether the component should ignore user interaction. |
| `form` | `string` | no | Identifies the form that owns the hidden input. Useful when the select is rendered outside the form. |
| `highlightItemOnHover` | `boolean` | no | Whether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state. |
| `id` | `string` | no | The id of the Select. |
| `inputRef` | `Ref<HTMLInputElement>` | no | A ref to access the hidden input element. |
| `isItemEqualToValue` | `((itemValue: Value, value: Value) => boolean)` | no | Custom comparison logic used to determine if a select item value matches the current selected value. Useful when item values are objects without matching referentially. Defaults to `Object.is` comparison. |
| `items` | `readonly Group<any>[] \| readonly { label: ReactNode; value: any; }[] \| Record<string, ReactNode>` | no | Data structure of the items rendered in the select popup. When specified, `<Select.Value>` renders the label of the selected item instead of the raw value. |
| `itemToStringLabel` | `((itemValue: Value) => string)` | no | When the item values are objects (`<Select.Item value={object}>`), this function converts the object value to a string representation for display in the trigger. If the shape of the object is `{ value, label }`, the label will be used automatically without needing to specify this prop. |
| `itemToStringValue` | `((itemValue: Value) => string)` | no | When the item values are objects (`<Select.Item value={object}>`), this function converts the object value to a string representation for form submission. If the shape of the object is `{ value, label }`, the value will be used automatically without needing to specify this prop. |
| `modal` | `boolean` | no | Determines if the select enters a modal state when open. - `true`: user interaction is limited to the select: document page scroll is locked and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed.  On touch devices, a `true` modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior. |
| `multiple` | `Multiple` | no | Whether multiple items can be selected. |
| `name` | `string` | no | Identifies the field when a form is submitted. |
| `onOpenChange` | `((open: boolean, eventDetails: SelectRootOpenChangeEventDetails) => void)` | no | Event handler called when the select popup is opened or closed. |
| `onOpenChangeComplete` | `((open: boolean) => void)` | no | Event handler called after any animations complete when the select popup is opened or closed. |
| `onValueChange` | `((value: SelectOutputValue<Value, Multiple> \| (Multiple extends true ? never : null), eventDetails: SelectRootChangeEventDetails) => void)` | no | Event handler called when the value of the select changes. |
| `open` | `boolean` | no | Whether the select popup is currently open. |
| `readOnly` | `boolean` | no | Whether the user should be unable to choose a different option from the select popup. |
| `required` | `boolean` | no | Whether the user must choose a value before submitting a form. |
| `value` | `SelectInputValue<Value, Multiple> \| null` | no | The value of the select. Use when controlled. |

### SelectContent

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `align` | `Align` | no | How to align the popup relative to the specified side. |
| `alignItemWithTrigger` | `boolean` | no | Whether the positioner overlaps the trigger so the selected item's text is aligned with the trigger's value text. This only applies to mouse input and is automatically disabled if there is not enough space. |
| `alignOffset` | `number \| OffsetFunction` | no | Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment.  The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. |
| `children` | `ReactNode` | no |  |
| `finalFocus` | `boolean \| RefObject<HTMLElement \| null> \| ((closeType: InteractionType) => boolean \| HTMLElement \| null \| void)` | no | Determines the element to focus when the select popup is closed.  - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing. |
| `render` | `ComponentRenderFn<HTMLProps, SelectPopupState> \| ReactElement<unknown, string \| JSXElementConstructor<any>>` | no | Allows you to replace the component's HTML element with a different tag, or compose it with another component.  Accepts a `ReactElement` or a function that returns the element to render. |
| `side` | `Side` | no | Which side of the anchor element to align the popup against. May automatically change to avoid collisions. |
| `sideOffset` | `number \| OffsetFunction` | no | Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment.  The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. |

### Other parts

**SelectGroup**

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `render` | `ComponentRenderFn<HTMLProps, SelectGroupState> \| ReactElement<unknown, string \| JSXElementConstructor<any>>` | no | Allows you to replace the component's HTML element with a different tag, or compose it with another component.  Accepts a `ReactElement` or a function that returns the element to render. |

**SelectItem**

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | no |  |
| `disabled` | `boolean` | no | Whether the component should ignore user interaction. |
| `label` | `string` | no | Specifies the text label to use when the item is matched during keyboard text navigation.  Defaults to the item text content if not provided. |
| `nativeButton` | `boolean` | no | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button. |
| `render` | `ComponentRenderFn<HTMLProps, SelectItemState> \| ReactElement<unknown, string \| JSXElementConstructor<any>>` | no | Allows you to replace the component's HTML element with a different tag, or compose it with another component.  Accepts a `ReactElement` or a function that returns the element to render. |
| `value` | `any` | no | A unique value that identifies this select item. |

**SelectLabel**

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `render` | `ComponentRenderFn<HTMLProps, SelectGroupLabelState> \| ReactElement<unknown, string \| JSXElementConstructor<any>>` | no | Allows you to replace the component's HTML element with a different tag, or compose it with another component.  Accepts a `ReactElement` or a function that returns the element to render. |

**SelectScrollDownButton**

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `keepMounted` | `boolean` | no | Whether to keep the HTML element in the DOM while the select popup is not scrollable. |
| `render` | `ComponentRenderFn<HTMLProps, SelectScrollDownArrowState> \| ReactElement<unknown, string \| JSXElementConstructor<any>>` | no | Allows you to replace the component's HTML element with a different tag, or compose it with another component.  Accepts a `ReactElement` or a function that returns the element to render. |

**SelectScrollUpButton**

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `keepMounted` | `boolean` | no | Whether to keep the HTML element in the DOM while the select popup is not scrollable. |
| `render` | `ComponentRenderFn<HTMLProps, SelectScrollUpArrowState> \| ReactElement<unknown, string \| JSXElementConstructor<any>>` | no | Allows you to replace the component's HTML element with a different tag, or compose it with another component.  Accepts a `ReactElement` or a function that returns the element to render. |

**SelectSeparator**

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `orientation` | `Orientation` | no | The orientation of the separator. |
| `render` | `ComponentRenderFn<HTMLProps, SelectSeparatorState> \| ReactElement<unknown, string \| JSXElementConstructor<any>>` | no | Allows you to replace the component's HTML element with a different tag, or compose it with another component.  Accepts a `ReactElement` or a function that returns the element to render. |

**SelectTrigger**

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `size` | `"default" \| "sm"` | no | The height of the trigger: `default` (36 px) or `sm` (32 px). |
| `children` | `ReactNode` | no |  |
| `disabled` | `boolean` | no | Whether the component should ignore user interaction. |
| `nativeButton` | `boolean` | no | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
| `render` | `ComponentRenderFn<HTMLProps, SelectTriggerState> \| ReactElement<unknown, string \| JSXElementConstructor<any>>` | no | Allows you to replace the component's HTML element with a different tag, or compose it with another component.  Accepts a `ReactElement` or a function that returns the element to render. |

**SelectValue**

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `children` | `((value: any) => ReactNode) \| ReactNode` | no | Accepts a function that returns a `ReactNode` to format the selected value. Treat the value as read-only: in `multiple` mode it may be a shared frozen array when nothing is selected. |
| `placeholder` | `ReactNode` | no | The placeholder value to display when no value is selected. This is overridden by `children` if specified, or by a null item's label in `items`. |
| `render` | `ComponentRenderFn<HTMLProps, SelectValueState> \| ReactElement<unknown, string \| JSXElementConstructor<any>>` | no | Allows you to replace the component's HTML element with a different tag, or compose it with another component.  Accepts a `ReactElement` or a function that returns the element to render. |

> [!NOTE]
> **Based on shadcn/ui**
>
> This page adapts the Select documentation of shadcn/ui (MIT licence) to this
> package; see [Third-party notices](/third-party-notices).
