# Select

A conventional field for keeping one selected value from a predefined list. Select uses a compact button trigger and supports keyboard typeahead, but it does not show a search input or support multiple selection.

## When to Use

- Exactly one value should persist after the dropdown closes
- The option set is short enough to scan or navigate with keyboard typeahead
- A familiar compact field is preferable to an always-visible list
- The value should participate in form state and validation

Choose a different component when the interaction has another shape:

- Use [Picker](./Picker.md) when you need multiple selection, checkboxes, select-all, or a custom trigger summary.
- Use [FilterPicker](./FilterPicker.md) when users need a visible search field, especially for multiple selection.
- Use [ComboBox](./ComboBox.md) for an always-visible text input that searches and keeps one selected value.
- Use [SearchComboBox](./SearchComboBox.md) when choosing a result should fire an action and clear the input.
- Use [Menu](../actions/Menu.md) with `MenuTrigger` for navigation or actions that do not represent a field value.
- Use [RadioGroup](./RadioGroup.md) when a small set of choices should remain visible for direct comparison.

## Component

---

### Properties

- **`selectedKey`** `string` — The selected value in controlled mode
- **`defaultSelectedKey`** `string` — The default selected value in uncontrolled mode
- **`placeholder`** `string` — Placeholder text when no option is selected
- **`icon`** `ReactElement` — Icon element rendered before the select value
- **`rightIcon`** `ReactNode` — Icon element rendered after the select value (caret by default)
- **`prefix`** `ReactNode` — Content rendered before the select value
- **`suffix`** `ReactNode` — Content rendered after the select value
- **`shape`** `'card' | 'button' | 'sharp' | 'pill'` (default: `button`) — Shape of the trigger border radius
- **`suffixPosition`** `string` (default: `before`) — Position of suffix relative to validation icons
- **`type`** `string` (default: `outline`) — Visual style variant of the select
- **`theme`** `string` (default: `default`) — Theme variant affecting overall styling
- **`size`** `string` (default: `medium`) — Size of the trigger and of the options in its list (a `small` trigger opens `medium` options)
- **`direction`** `string` (default: `bottom`) — Preferred direction for the dropdown menu
- **`isClearable`** `boolean` (default: `false`) — Whether the select is clearable using a clear button in the rightIcon slot
- **`clearLabel`** `string` — Accessible name for the built-in clear button. Defaults to a localized "Clear value".
- **`actions`** `ReactNode` — Custom actions rendered inside the trigger, to the left of the built-in clear button and dropdown caret
- **`shouldFlip`** `boolean` (default: `true`) — Whether dropdown should flip to fit in viewport
- **`placement`** `Placement` (default: `${direction} end`) — Placement of the popover relative to the anchor, as a React Aria placement string (e.g. `'bottom start'`, `'top end'`)
- **`targetRef`** `RefObject<HTMLElement | null>` — The element the popover visually attaches to. Defaults to the trigger; use it to anchor the popover to an outer container so sibling controls' popovers line up
- **`overlayOffset`** `number` (default: `8`) — Distance between select and dropdown in pixels
- **`items`** `Iterable<T>` — Item objects used when rendering dynamic collections
- **`disabledKeys`** `Iterable<Key>` — Keys of items that are disabled
- **`children`** `ReactNode | (item: T) => ReactElement` — Static child items or render function for dynamic items
- **`triggerRef`** `RefObject<HTMLButtonElement>` — Ref for the trigger button element
- **`popoverRef`** `RefObject<HTMLElement | null>` — Ref for the popover overlay element
- **`listBoxRef`** `RefObject<HTMLElement>` — Ref for the list box element
- **`isLoading`** `boolean` — Shows a loading indicator in the trigger and fixes the value until loading ends
- **`loadingIndicator`** `ReactNode` — Replaces the default loading icon shown while `isLoading` is set
- **`styles`** `Styles` — Styles for the root wrapper element
- **`inputStyles`** `Styles` — Styles for the input trigger element
- **`listBoxStyles`** `Styles` — Styles for the dropdown list container
- **`optionStyles`** `Styles` — Styles for individual option items
- **`listGap`** `number` — Space between options, in pixels. Defaults to a hairline (`$item-gap`, `1px`)
- **`overlayStyles`** `Styles` — Styles for the dropdown overlay wrapper
- **`triggerStyles`** `Styles` — Styles for the trigger button element
- **`inputProps`** `Props` — Additional props for the trigger button element
- **`autoFocus`** `boolean` — Focuses the trigger when it mounts
- **`triggerDescription`** `ReactNode` — Description text displayed within the trigger button (different from field-level description)
- **`descriptionPlacement`** `'inline' | 'block'` — Controls how the trigger description is positioned
- **`hotkeys`** `string` — Keyboard shortcut that triggers the select when pressed
- **`tooltip`** `string | boolean | object` — Tooltip on the trigger (see [Notable Properties](#notable-properties)). The info badge next to the label is the field-level `labelTooltip`
- **`containerPadding`** `number` (default: `8`) — Minimum padding in pixels between the popover and viewport edges
- **`isOpen`** `boolean` — Whether the dropdown is open (controlled)
- **`defaultOpen`** `boolean` — Whether the dropdown is open by default (uncontrolled)
- **`selectionMode`** `'single'` — Selection mode for the select
- **`onSelectionChange`** `(key: Key | null) => void` — Callback fired when the selected option changes. Clearing the selection passes `null`
- **`onOpenChange`** `(isOpen: boolean) => void` — Callback fired when the dropdown opens or closes
- **`onFocus`** `(e: FocusEvent) => void` — Callback fired when the select receives focus
- **`onBlur`** `(e: FocusEvent) => void` — Callback fired when the select loses focus
- **`onFocusChange`** `(isFocused: boolean) => void` — Callback fired when focus state changes
- **`aria-label`** `string` — Accessible label when no visible label exists
- **`aria-labelledby`** `string` — ID of element that labels the select
- **`aria-describedby`** `string` — ID of element that describes the select

#### Notable Properties

**isClearable** - Adds a clear button in the rightIcon slot that allows users to clear the selected value. The clear button only appears when a value is selected and the select is not disabled or read-only.

**onClear** - Callback fired when the clear button is pressed, allowing you to perform custom actions when the selection is cleared.

**isReadOnly** and **isLoading** - The trigger stays focusable and keeps its accessible name, but the value can't change: the list doesn't open, typeahead and the arrow keys don't pick another option, and the clear button is hidden. If either one, or `isDisabled`, turns on while the list is open, the list closes.

**actions** - Your own controls inside the trigger, rendered to the left of the built-in clear button and dropdown caret. Pressing one runs its handler without opening or closing the popover — including while the popover is open — so an action can do something the clear button cannot, such as restoring a default selection instead of emptying it. Use `Select.Action` so they match the trigger's size and theme. Actions follow the trigger's disabled state but not `isReadOnly`; pass `isDisabled` yourself for an action that changes the value.

**tooltip** - Enables tooltip display on the trigger button. Can be:

- `string` - Simple tooltip text
- `true` - Auto tooltip on overflow (shows selected value when truncated)
- `object` - Advanced configuration with optional `auto` property

It belongs to the trigger alone. The info badge next to the field's label is `labelTooltip` — before that prop existed, a `tooltip` on a labelled Select rendered in both places.

**triggerDescription** - Text description displayed within the trigger button. Different from field-level description provided by FieldWrapper.

**descriptionPlacement** - Controls how description is positioned: `inline` or `block`.

**overlayOffset** - Distance between the select trigger and dropdown in pixels (default: 8).

**direction** - Preferred direction for the dropdown: `top` or `bottom` (default: `bottom`).

**shouldFlip** - Whether the dropdown should flip to fit in viewport (default: `true`).

**suffixPosition** - Position of suffix content relative to validation icons: `before` or `after` (default: `before`).

### Base Properties

Supports [Base properties](../../BaseProperties.md)

### Field Properties

Supports all [Field properties](../../FieldProperties.md)

### Styling Properties

#### styles

Customizes the root wrapper element of the component.

#### triggerStyles

Customizes the trigger button element that opens the dropdown.

**Sub-elements:**

- `Label` - The displayed selected value text or placeholder
- `Prefix` - Container for prefix content
- `Suffix` - Container for suffix content
- `Icon` - Container for left icon
- `RightIcon` - Container for right icon (caret, loading, clear button)
- `Description` - Description text within the trigger
- `Hotkeys` - Keyboard shortcut display

#### listBoxStyles

Customizes the dropdown list container that displays options.

#### overlayStyles

Customizes the popover overlay wrapper that contains the list.

#### optionStyles

Customizes individual option items in the dropdown.

**Sub-elements:**

- `Label` - The main content/text of the option
- `Description` - Secondary description text
- `Prefix` - Container for prefix content
- `Suffix` - Container for suffix content
- `Icon` - Container for left icon
- `RightIcon` - Container for right icon

### Style Properties

These properties allow direct style application without using the `styles` prop:

- **Position:** `gridArea`, `order`, `gridColumn`, `gridRow`, `placeSelf`, `alignSelf`, `justifySelf`, `zIndex`, `margin`, `blockMargin`, `inlineMargin`, `inset`, `blockInset`, `inlineInset`, `position`, `scrollMargin`, `blockScrollMargin`, `inlineScrollMargin`, `scrollPadding`, `blockScrollPadding`, `inlineScrollPadding`
- **Dimension:** `width`, `height`, `blockSize`, `inlineSize`, `flexBasis`, `flexGrow`, `flexShrink`, `flex`

### Modifiers

The `mods` property accepts the following modifiers you can override:

- `focused` `boolean` — Whether the select has focus
- `disabled` `boolean` — Whether the select is disabled
- `invalid` `boolean` — Whether the select has validation errors
- `valid` `boolean` — Whether the select is valid
- `placeholder` `boolean` — Whether showing placeholder text
- `hovered` `boolean` — Whether the select is being hovered
- `loading` `boolean` — Whether the select is in loading state
- `prefix` `boolean` — Whether prefix content is present
- `suffix` `boolean` — Whether suffix content is present

## Sub-components

### Select.Item

Individual option items within the select dropdown. Each item is rendered using [Item](../content/Item.md) and supports all Item properties for layout, icons, descriptions, and interactive features.

#### Item API

For detailed information about all available item properties, see [Item documentation](../content/Item.md). Key properties include:

- **`key`** `string \| number` — Unique identifier for the item (required)
- **`children`** `ReactNode` — The main content/label for the option
- **`icon`** `ReactNode` — Icon displayed before the content
- **`rightIcon`** `ReactNode` — Icon displayed after the content
- **`description`** `ReactNode` — Secondary text below the main content
- **`descriptionPlacement`** `'inline' \| 'block'` — How the description is positioned
- **`prefix`** `ReactNode` — Content before the main text
- **`suffix`** `ReactNode` — Content after the main text
- **`tooltip`** `string \| boolean \| object` — Tooltip configuration
- **`styles`** `Styles` — Custom styling for the item
- **`qa`** `string` — QA identifier for testing

#### Example with Rich Items

```jsx
<Select label="Users">
  <Select.Item
    key="user1"
    icon={<IconUser />}
    description="Administrator"
  >
    John Doe
  </Select.Item>
  <Select.Item
    key="user2"
    icon={<IconUser />}
    description="Editor"
    suffix="Online"
  >
    Jane Smith
  </Select.Item>
</Select>
```

### Select.Action

An [ItemAction](../actions/ItemAction.md) re-exported for the `actions` slot. It picks up the trigger's size and theme, so an action matches the field it sits in without being configured. Give every icon-only action an `aria-label` (a `tooltip` string also supplies one), since the icon alone has no accessible name.

```jsx
<Select
  label="Color"
  actions={<Select.Action icon={<ReloadIcon />} aria-label="Reset" onPress={reset} />}
>
  {items}
</Select>
```

### Select.Section

Groups related options together with an optional heading.

- **`title`** `ReactNode` — Optional heading text for the section
- **`children`** `Select.Item[]` — Collection of Select.Item components

## Variants

### Themes

- `default` - Standard select appearance
- `special` - Alternative styling for special contexts

### Types

- `primary` - Primary emphasis styling
- `outline` - Outlined appearance; `isSelected` adds brand-tinted fill
- `clear` - Minimal appearance; `isSelected` adds brand-tinted fill
- `link` - Link-like appearance

### Sizes

- `small` - Compact size for dense interfaces
- `medium` - Standard size for general interfaces (default)
- `large` - Emphasized size for important selections

## Examples

### Basic Usage

```jsx
<Select label="Choose an option">
  <Select.Item key="option1">Option 1</Select.Item>
  <Select.Item key="option2">Option 2</Select.Item>
  <Select.Item key="option3">Option 3</Select.Item>
</Select>
```

### With Default Value

```jsx
<Select label="Color" defaultSelectedKey="purple">
  <Select.Item key="red">Red</Select.Item>
  <Select.Item key="blue">Blue</Select.Item>
  <Select.Item key="purple">Purple</Select.Item>
</Select>
```

### With Placeholder

```jsx
<Select label="Country" placeholder="Select a country">
  <Select.Item key="us">United States</Select.Item>
  <Select.Item key="ca">Canada</Select.Item>
  <Select.Item key="uk">United Kingdom</Select.Item>
</Select>
```

### Clearable

```jsx
<Select
  isClearable
  label="Color"
  defaultSelectedKey="blue"
  placeholder="Choose a color..."
>
  <Select.Item key="red">Red</Select.Item>
  <Select.Item key="blue">Blue</Select.Item>
  <Select.Item key="green">Green</Select.Item>
</Select>
```

### With Custom Actions

#### Where the trailing controls live

Your actions, the clear button and the caret share one run, rendered **outside** the trigger `<button>` and laid over its trailing end — the same layout `ItemButton` uses for a row's actions. The clear button is therefore a real sibling of the trigger rather than a `<button>` nested inside one, and the run reserves its width so nothing overlaps the label.

The caret is in that run too, and still opens the popover: the run is transparent to the pointer and only its interactive children take presses, so a press on the caret — or anywhere in the run's padding — hit-tests through to the trigger underneath.

`rightIcon` is the one thing that stays in its own slot, because it accepts a render function resolved against the trigger's modifiers and is what a caller's `RightIcon` styles target. Passing it replaces the built-in caret exactly as before; if you pass `actions` as well, they render after it.

The run is rendered whether or not it has anything in it, so the trigger's markup does not change shape as a clear button appears or a spinner replaces the caret. `rightIcon={null}` empties it — the caret moves into the `rightIcon` slot and nothing takes its place — and an empty run reserves nothing, so an icon-only trigger stays square.

```jsx
const DEFAULT_KEY = 'blue';

<Select
  isClearable
  label="Color"
  placeholder="Choose a color..."
  selectedKey={selectedKey}
  actions={
    selectedKey !== DEFAULT_KEY ? (
      <Select.Action
        icon={<ReloadIcon />}
        aria-label="Reset to default"
        tooltip="Reset to default"
        onPress={() => setSelectedKey(DEFAULT_KEY)}
      />
    ) : null
  }
  onSelectionChange={setSelectedKey}
>
  <Select.Item key="red">Red</Select.Item>
  <Select.Item key="blue">Blue</Select.Item>
</Select>
```

### Validation States

```jsx
{/* Valid state */}
<Select
  label="Validated field"
  selectedKey="yes"
  isValid
>
  <Select.Item key="yes">Yes</Select.Item>
  <Select.Item key="no">No</Select.Item>
</Select>

{/* Invalid state */}
<Select
  label="Required field"
  isInvalid
  errorMessage="Please select an option"
>
  <Select.Item key="yes">Yes</Select.Item>
  <Select.Item key="no">No</Select.Item>
</Select>
```

### Disabled State

```jsx
<Select
  isDisabled
  label="Disabled select"
  selectedKey="option1"
>
  <Select.Item key="option1">Cannot change</Select.Item>
  <Select.Item key="option2">Option 2</Select.Item>
</Select>
```

### With Icon

```jsx
<Select label="Currency" icon={<IconCoin />}>
  <Select.Item key="usd">USD</Select.Item>
  <Select.Item key="eur">EUR</Select.Item>
  <Select.Item key="gbp">GBP</Select.Item>
</Select>
```

### With Description

```jsx
<Select placeholder="Select a color" listBoxStyles={{ width: 'max 30x' }}>
  <Select.Item key="red" description="The color of fire">
    Red
  </Select.Item>
  <Select.Item key="green" description="The color of nature">
    Green
  </Select.Item>
  <Select.Item key="blue" description="The color of the sky">
    Blue
  </Select.Item>
</Select>
```

### With Icons and Descriptions

```jsx
<Select placeholder="Select a color">
  <Select.Item
    key="yellow"
    description="Child and light"
    icon={<IconUser />}
  >
    Yellow
  </Select.Item>
  <Select.Item
    key="red"
    description="Hot and strong"
    prefix={<span>🔥</span>}
  >
    Red
  </Select.Item>
  <Select.Item
    key="green"
    description="Fresh and calm"
    suffix={<Text color="#dark-03">#00A000</Text>}
  >
    Green
  </Select.Item>
</Select>
```

### With Sections (Static)

```jsx
<Select placeholder="Pick something">
  <Select.Section title="Warm colors">
    <Select.Item key="red">Red</Select.Item>
    <Select.Item key="orange">Orange</Select.Item>
    <Select.Item key="yellow">Yellow</Select.Item>
  </Select.Section>
  <Select.Section title="Cool colors">
    <Select.Item key="blue">Blue</Select.Item>
    <Select.Item key="purple">Purple</Select.Item>
  </Select.Section>
</Select>
```

### With Sections (Dynamic)

Sections and items can be defined dynamically using the `items` prop with a render function.

```jsx
const groups = [
  {
    name: 'Fruits',
    children: [
      { id: 'apple', label: 'Apple' },
      { id: 'orange', label: 'Orange' },
    ],
  },
  {
    name: 'Vegetables',
    children: [
      { id: 'carrot', label: 'Carrot' },
      { id: 'peas', label: 'Peas' },
    ],
  },
];

<Select items={groups} placeholder="Choose an item">
  {(group) => (
    <Select.Section key={group.name} title={group.name} items={group.children}>
      {(item) => <Select.Item key={item.id}>{item.label}</Select.Item>}
    </Select.Section>
  )}
</Select>
```

### With Tooltips

```jsx
<Select placeholder="Choose a framework">
  <Select.Item
    key="react"
    tooltip="React - A JavaScript library for building user interfaces"
  >
    React
  </Select.Item>
  <Select.Item
    key="vue"
    tooltip={{ title: 'Vue.js Framework' }}
  >
    Vue.js
  </Select.Item>
  <Select.Item
    key="angular"
    tooltip="Angular - Platform for building mobile and desktop web applications"
  >
    Angular
  </Select.Item>
</Select>
```

### With Disabled Items

```jsx
<Select disabledKeys={['red']}>
  <Select.Item key="red">Red (disabled)</Select.Item>
  <Select.Item key="blue">Blue</Select.Item>
  <Select.Item key="green">Green</Select.Item>
</Select>
```

## Accessibility

### Keyboard Navigation

- `Tab` - Moves focus to the select
- `Space/Enter` - Opens the dropdown on the selected option, or the first one you can pick
- `Arrow Down` - Opens the dropdown on the selected option, or the first one you can pick; moves to the next option when open
- `Arrow Up` - Opens the dropdown on the last option you can pick; moves to the previous option when open. A disabled option is reached too, as WAI-ARIA keeps it focusable, so a screen reader says why it is unavailable; Enter ignores it
- `Page Down/Page Up` - Moves about one visible page of options
- `Home` - Moves to first option
- `End` - Moves to last option
- `Escape` - Closes dropdown without selecting
- `Enter` - Selects focused option and closes dropdown
- Typing - Navigates to options starting with typed character

Opened with a pointer, the list focuses the selected option, or the list itself when nothing is selected. The focused option is scrolled into view as the list opens.

### Screen Reader Support

- The trigger announces as a button with a listbox popup, named by the value it shows and its label, and described by its description and error message
- Current selection is announced when changed
- Available options are announced during navigation
- Dropdown state (open/closed) is communicated

### ARIA Properties

The trigger button carries:

- `aria-label` - Provides accessible label when no visible label exists
- `aria-labelledby` - References the selected value, the label and any `aria-labelledby` you pass
- `aria-describedby` - References the description and the error message, and your own descriptive text
- `aria-haspopup="listbox"` - Indicates that the trigger opens a list
- `aria-expanded` - Indicates if dropdown is open
- `aria-controls` - References the list while it is open

The open list is a `listbox`. Options take DOM focus as you move through them, so the trigger has no `aria-activedescendant`.

## Best Practices

1. **Do**: Provide clear, descriptive labels and meaningful option text

   ```jsx
   <Select label="Shipping method">
     <Select.Item key="standard">Standard (5-7 days)</Select.Item>
     <Select.Item key="express">Express (2-3 days)</Select.Item>
   </Select>
   ```

2. **Don't**: Use select for very long lists (use ComboBox or FilterPicker with search instead)

   ```jsx
   {/* Consider ComboBox or FilterPicker for 50+ options */}
   <Select label="Country">
     {/* 100+ countries... */}
   </Select>
   ```

3. **Do**: Use sections to group related options logically

   ```jsx
   <Select label="Category">
     <Select.Section title="Popular">
       <Select.Item key="featured1">Featured Option 1</Select.Item>
     </Select.Section>
     <Select.Section title="All Options">
       <Select.Item key="all1">All Option 1</Select.Item>
     </Select.Section>
   </Select>
   ```

4. **Do**: Provide clear error messages for validation failures

   ```jsx
   <Select
     isRequired
     isInvalid
     errorMessage="Please select a shipping method"
     label="Shipping"
   >
     <Select.Item key="standard">Standard</Select.Item>
   </Select>
   ```

5. **Do**: Consider providing sensible defaults when appropriate

   ```jsx
   <Select label="Language" defaultSelectedKey="en">
     <Select.Item key="en">English</Select.Item>
     <Select.Item key="es">Spanish</Select.Item>
   </Select>
   ```

6. **Do**: Show loading state when options are being fetched

   ```jsx
   <Select isLoading label="Categories" placeholder="Loading...">
     {categories.map(cat => <Select.Item key={cat.id}>{cat.name}</Select.Item>)}
   </Select>
   ```

7. **Accessibility**: Always provide meaningful labels

   ```jsx
   <Select label="Country" aria-label="Select your country">
     <Select.Item key="us">United States</Select.Item>
   </Select>
   ```

8. **Clearable**: Use `isClearable` for optional selections
   ```jsx
   <Select isClearable label="Filter by status" placeholder="All statuses">
     <Select.Item key="active">Active</Select.Item>
     <Select.Item key="inactive">Inactive</Select.Item>
   </Select>
   ```

## Integration with Forms

This component supports all [Field properties](../../FieldProperties.md) when used within a Form. It integrates seamlessly with the form validation system and supports both controlled and uncontrolled modes.

```jsx
function Example() {
  const form = Form.useController();
  return (
    <Form form={form}>
      <Select
        name="country"
        label="Country"
        isRequired
      >
        <Select.Item key="us">United States</Select.Item>
        <Select.Item key="uk">United Kingdom</Select.Item>
        <Select.Item key="ca">Canada</Select.Item>
      </Select>
    </Form>
  );
}
```

## Suggested Improvements

- Add support for multi-selection mode with visual badges
- Implement virtual scrolling for very large option lists (1000+ items)
- Built-in async loading support with loading states per scroll position
- Custom empty state component when no options are available
- Support for option groups with visual separators beyond sections

## Related Components

- [Picker](./Picker.md) - For richer button-triggered selection, including multiple values
- [FilterPicker](./FilterPicker.md) - For button-triggered selection with a visible search field
- [ComboBox](./ComboBox.md) - For an input-based searchable field that keeps one selected value
- [SearchComboBox](./SearchComboBox.md) - For search-and-act flows that clear after each result
- [ListBox](./ListBox.md) - A standalone, always-visible list. Select renders its own list, not ListBox
- [RadioGroup](./RadioGroup.md) - For visible selection options with fewer choices
- [Menu](../actions/Menu.md) - For action-oriented or navigation dropdowns
- [Item](../content/Item.md) - The base component used for rendering items
