# Select

A Select is used to present a defined list of options to choose from.

## Design & usage guidelines

Nested within the Select component, Option defines the options that can be
selected. For grouping options with section headers, use Select.OptionGroup.

#### Custom grouped menu and browser support

To enable the enhanced grouped menu styling (bold section headers, edge‑to‑edge
dividers and hover backgrounds), set the `UNSAFE_experimentalStyles` prop on
`Select`.

* When `UNSAFE_experimentalStyles` is true and the browser supports
  `appearance: base-select` (Chromium 123+), the select renders with the
  customizable grouped menu.
* In unsupported browsers, or when `UNSAFE_experimentalStyles` is not provided,
  the select remains native while still rendering the same `OptionGroup`
  structure.

## States

### Invalid

```tsx
import React, { useState } from "react";
import { Option, Select } from "@jobber/components/Select";

export function SelectInvalidExample() {
  const [value, setValue] = useState<string | number | undefined>("");

  return (
    <Select invalid={true} value={value} onChange={setValue}>
      <Option value="sad">Tony</Option>
      <Option value="old">Steve</Option>
    </Select>
  );
}
```

### Disabled

```tsx
import React, { useState } from "react";
import { Option, Select } from "@jobber/components/Select";

export function SelectDisabledExample() {
  const [value, setValue] = useState<string | number | undefined>("");

  return (
    <Select disabled={true} value={value} onChange={setValue}>
      <Option value="sad">Tony</Option>
      <Option value="old">Steve</Option>
    </Select>
  );
}
```

## Option Grouping

Use `Select.OptionGroup` to organize options with section headers for better
user experience and visual hierarchy. The `label` prop is required as it
provides the section header text.

### Basic Option Groups

```tsx
import React, { useState } from "react";
import { Select } from "@jobber/components/Select";

export function SelectCustomOptionGroupsExample() {
  const [value, setValue] = useState<string | number | undefined>("");

  return (
    <Select
      placeholder="Select an option"
      UNSAFE_experimentalStyles={true}
      value={value}
      onChange={setValue}
    >
      <Select.OptionGroup label="Team A">
        <Select.Option value="alice">Alice</Select.Option>
        <Select.Option value="bob">Bob</Select.Option>
        <Select.Option value="charlie">Charlie</Select.Option>
      </Select.OptionGroup>
      <Select.OptionGroup label="Team B">
        <Select.Option value="diana">Diana</Select.Option>
        <Select.Option value="evan">Evan</Select.Option>
        <Select.Option value="frank">Frank</Select.Option>
      </Select.OptionGroup>
      <Select.OptionGroup label="Team C">
        <Select.Option value="grace">Grace</Select.Option>
        <Select.Option value="hector">Hector</Select.Option>
        <Select.Option value="isabel">Isabel</Select.Option>
      </Select.OptionGroup>
    </Select>
  );
}
```

### Disabled Option Groups

```tsx
import React, { useState } from "react";
import { Select } from "@jobber/components/Select";

export function SelectCustomOptionGroupDisabledExample() {
  const [value, setValue] = useState<string | number | undefined>("");

  return (
    <Select
      UNSAFE_experimentalStyles
      placeholder="Select an option"
      value={value}
      onChange={setValue}
    >
      <Select.OptionGroup label="Available Items">
        <Select.Option value="option1">Option 1</Select.Option>
        <Select.Option value="option2">Option 2</Select.Option>
      </Select.OptionGroup>
      <Select.OptionGroup label="Unavailable Items" disabled>
        <Select.Option value="option3">Option 3</Select.Option>
        <Select.Option value="option4">Option 4</Select.Option>
      </Select.OptionGroup>
      <Select.OptionGroup label="More Items">
        <Select.Option value="option5">Option 5</Select.Option>
        <Select.Option value="option6">Option 6</Select.Option>
      </Select.OptionGroup>
    </Select>
  );
}
```


## Configuration

### Custom (Chromium) vs native

Select is native by default. Opt into the customizable Chrome UI with
`UNSAFE_experimentalStyles`. This enhances grouped menus in Chromium 123+ when
the browser supports `appearance: base-select`.

#### Alignment limitation (custom UI)

When using `UNSAFE_experimentalStyles`, the closed control (what you see as the
displayed value) is still rendered by the browser's picker. As a result,
right/center alignment of the displayed value is not configurable in Chromium's
customizable select.

* Need right/center alignment? Use the native Select (omit
  `UNSAFE_experimentalStyles`).
* You can still style the grouped dropdown (optgroup/option) in the custom UI,
  but the closed value alignment will remain default.

## Component customization

### Composable usage

Select supports composition via subcomponents:

* `Select.Option`: item in the list. Provide `value` and children as the label.
* `Select.OptionGroup`: group options under a `label`. Use with
  `UNSAFE_experimentalStyles` to opt into the customizable grouped menu in
  Chromium.

#### Customization links

* See
  ["A customizable select"](https://developer.chrome.com/blog/a-customizable-select)
  article for what the Chrome UI exposes: `::picker(select)`, option/optgroup
  styling, and transitions.

## UNSAFE\_ props (advanced usage)

General guidance on `UNSAFE_` props can be found in
[Customizing components](../customizing-components/customizing-components.md).

Select subcomponents allow `UNSAFE_className` and `UNSAFE_style` to target the
native elements:

* `Select.OptionGroup` maps to `<optgroup>`
* `Select.Option` maps to `<option>`

Note that native `<select>` UX differs per browser. Use `UNSAFE_` props with
caution and test across environments. In the custom UI (Chromium), only the
dropdown content is stylable; the closed value alignment is not.


## Props

### Web

#### Select

| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| `align` | `"center" | "right"` | No | — | Determines the alignment of the text inside the input. |
| `aria-activedescendant` | `string` | No | — | ID of the currently active descendant element. Used for composite widgets like combobox or listbox. @see {@link https... |
| `aria-autocomplete` | `"both" | "inline" | "list" | "none"` | No | — | Indicates the type of autocomplete interaction. @see {@link https://www.w3.org/TR/wai-aria-1.2/#aria-autocomplete} |
| `aria-controls` | `string` | No | — | Indicates the element that controls the current element. @see {@link https://www.w3.org/TR/wai-aria-1.2/#aria-controls} |
| `aria-describedby` | `string` | No | — | Identifies the element (or elements) that describes the object. @see {@link https://www.w3.org/TR/wai-aria-1.2/#aria-... |
| `aria-details` | `string` | No | — | Identifies the element (or elements) that provide a detailed, extended description. @see {@link https://www.w3.org/TR... |
| `aria-expanded` | `Booleanish` | No | — | Indicates whether the element is expanded or collapsed. @see {@link https://www.w3.org/TR/wai-aria-1.2/#aria-expanded} |
| `aria-label` | `string` | No | — | Defines a string value that labels the current element. @see {@link https://www.w3.org/TR/wai-aria-1.2/#aria-label} |
| `aria-labelledby` | `string` | No | — | Identifies the element (or elements) that labels the current element. @see {@link https://www.w3.org/TR/wai-aria-1.2/... |
| `aria-required` | `Booleanish` | No | — | Indicates that user input is required before form submission. @see {@link https://www.w3.org/TR/wai-aria-1.2/#aria-re... |
| `autoComplete` | `string` | No | — | Autocomplete behavior for the input (React casing, string values only). Use standard HTML autocomplete values or "on"... |
| `autoFocus` | `boolean` | No | — | Whether the input should be auto-focused (React casing). |
| `children` | `ReactNode` | No | — | If you need to pass in a children. For example, `<options>` inside `<select>`. |
| `description` | `ReactNode` | No | — | Further description of the input, can be used for a hint. |
| `disabled` | `boolean` | No | — | Whether the input is disabled. |
| `error` | `string` | No | — | Error message to display. This also highlights the field red. |
| `id` | `string` | No | — | The unique identifier for the input element. |
| `inline` | `boolean` | No | — | Adjusts the form field to go inline with content. |
| `inputMode` | `"decimal" | "email" | "none" | "numeric" | "search" | "tel" | "text" | "url"` | No | — | Input mode hint for virtual keyboards. |
| `inputRef` | `Ref<HTMLSelectElement>` | No | — |  |
| `invalid` | `boolean` | No | — | Highlights the field red to indicate an error. |
| `loading` | `boolean` | No | — | Show a spinner to indicate loading. |
| `name` | `string` | No | — | The name attribute for the input element. |
| `onBlur` | `(event: FocusEvent<HTMLSelectElement, Element>) => void` | No | — | Blur event handler. |
| `onChange` | `(newValue?: string | number) => void` | No | — |  |
| `onEnter` | `(event: KeyboardEvent<Element>) => void` | No | — | @deprecated Use `onKeyDown` or `onKeyUp` instead. |
| `onFocus` | `(event: FocusEvent<HTMLSelectElement, Element>) => void` | No | — | Focus event handler. |
| `pattern` | `string` | No | — | Validation pattern (regex) for the input. |
| `placeholder` | `string` | No | — | Text that appears inside the input when empty and floats above the value as a mini label once the user enters a value... |
| `prefix` | `Affix` | No | — | Adds a prefix label and icon to the field |
| `required` | `boolean` | No | — | Whether the input is required before form submission. |
| `role` | `string` | No | — | Role attribute for accessibility. |
| `size` | `"large" | "small"` | No | — | Adjusts the interface to either have small or large spacing. |
| `suffix` | `{ onClick: () => void; readonly ariaLabel: string; readonly icon: IconNames; readonly label?: string; } | { onClick?: never; ariaLabel?: never; readonly label?: string; readonly icon?: IconNames; }` | No | — | Adds a suffix label and icon with an optional action to the field |
| `tabIndex` | `number` | No | — | Tab index for keyboard navigation. |
| `UNSAFE_experimentalStyles` | `boolean` | No | — | Opt-in to the customizable select UI (Chromium 123+). When true, the component will apply the custom select styles De... |
| `value` | `number | string` | No | — |  |

#### Select.Option

| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| `disabled` | `boolean` | No | — |  |
| `value` | `string` | No | — | The content of this attribute represents the value to be submitted with the form, should this option be selected. |

#### Select.OptionGroup

| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| `label` | `string` | Yes | — |  |
| `disabled` | `boolean` | No | — |  |
| `UNSAFE_className` | `string` | No | — | Use at your own risk: Custom classnames for specific elements. This should only be used as a last resort. Using this ... |
| `UNSAFE_style` | `{ container?: CSSProperties; }` | No | — | Use at your own risk: Custom style for specific elements. This should only be used as a last resort. Using this may r... |
