# Select

> Native select with a placeholder option, three sizes and a styled, animated picker where the browser supports it.

Source: https://docs.cherry.al/components/select

> For the complete documentation index, see [llms.txt](https://docs.cherry.al/llms.txt).

# Select

<Preview bleed>
<iframe className="light-only" src="https://v2.cherry.al/preview/select?theme=light" title="Select preview" loading="lazy" style={{ width: "100%", height: "566px" }} />
<iframe className="dark-only" src="https://v2.cherry.al/preview/select?theme=dark" title="Select preview" loading="lazy" style={{ width: "100%", height: "566px" }} />

```tsx
"use client";
import { Field, Select } from "@cherry-design-system/react";

export function Country() {
  return (
    <Field label="Country">
      <Select name="country" placeholder="Select a country">
        <option value="al">Albania</option>
        <option value="de">Germany</option>
        <option value="it">Italy</option>
      </Select>
    </Field>
  );
}
```
</Preview>

A native `<select>` for picking one option from a short, fixed list. Where the browser supports `appearance: base-select` the picker is styled and animated too; elsewhere the OS picker opens. Use [Combobox](/components/combobox) when the list is long and needs filtering.

## Examples

### Controlled

```tsx
"use client";
import { useState } from "react";
import { Field, Select } from "@cherry-design-system/react";

export function Sort() {
  const [sort, setSort] = useState("newest");
  return (
    <Field label="Sort by">
      <Select size="sm" value={sort} onChange={(e) => setSort(e.target.value)}>
        <option value="newest">Newest</option>
        <option value="oldest">Oldest</option>
        <option value="name">Name</option>
      </Select>
    </Field>
  );
}
```

### Option groups

```tsx
"use client";
import { Field, Select } from "@cherry-design-system/react";

export function Timezone() {
  return (
    <Field label="Time zone" required>
      <Select name="tz" placeholder="Select a time zone">
        <optgroup label="Europe">
          <option value="Europe/Tirane">Tirana</option>
          <option value="Europe/Berlin">Berlin</option>
        </optgroup>
        <optgroup label="America">
          <option value="America/New_York">New York</option>
        </optgroup>
      </Select>
    </Field>
  );
}
```

### Error

```tsx
"use client";
import { Field, Select } from "@cherry-design-system/react";

export function Role() {
  return (
    <Field label="Role" error="Choose a role.">
      <Select placeholder="Select a role">
        <option value="admin">Admin</option>
        <option value="member">Member</option>
      </Select>
    </Field>
  );
}
```

## Properties

<Field value="size" type='"sm" | "md" | "lg"'>
  Control size. Defaults to `"md"`.
</Field>

<Field value="invalid" type="boolean">
  Error state; set automatically inside a `<Field error>`.
</Field>

<Field value="placeholder" type="string">
  Text shown while no option is chosen (an empty, unselectable option).
</Field>

<Field value="wrapperClassName" type="string">
  Class for the outer wrapper (`className` goes to the `<select>`).
</Field>

<Field value="children" type="ReactNode">
  `<option>` and `<optgroup>` elements.
</Field>

The ref and all native `<select>` attributes go to the `<select>`.

## Styling

Root class `cherry-select` with `data-size` (`sm`, `md`, `lg`) and states `data-invalid`, `data-disabled`, `data-placeholder`, `:open`. Parts: `cherry-select__control`, `cherry-select__chevron`.

Reads the field tokens (`--cherry-bg-canvas`, `--cherry-border-default`, `--cherry-border-focus`, `--cherry-ring`) and, for the styled picker, `--cherry-bg-elevated`, `--cherry-elevation-lg` and `--cherry-ghost-hover`.

## Accessibility

Native `<select>`: full keyboard and screen reader support. Label it like Input, with Field or `aria-label`.

<Button href="https://github.com/cherry-design-system/react/tree/main/src/components/select" icon="code" iconPosition="left">
  View Source
</Button>
