# Select

> Native select with the same field finish as the input, a chevron over the right edge and an optional disabled placeholder option.

- Kind: ui · Category: Forms · Interactivity: native
- Install: `npx shadcn@latest add @haze/select`
- File: `src/components/haze/ui/select.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/select

## Use when
- Choosing one value from a list of roughly 4 to 15 fixed options
- Region, country, time zone or billing cycle pickers in forms
- Mobile-first forms where the operating system's own picker is the best experience

## Avoid when
- Two or three options that fit on screen; use radio-group or toggle-group
- Options that need icons, search or rich content

## Alternatives
- [radio-group](https://hazeui.com/ui/radio-group.md)
- [toggle-group](https://hazeui.com/ui/toggle-group.md)
- [dropdown-menu](https://hazeui.com/ui/dropdown-menu.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Element id; reference it from a label or Field. |
| name | `string` | id | no | Form field name. |
| options | `{ value: string; label: string; disabled?: boolean }[]` |  | yes | The choices, in display order. |
| value | `string` |  | no | Value of the option that is selected on load. |
| placeholder | `string` |  | no | Adds a disabled, empty first option with this text; it is selected only when no value is given. |
| required | `boolean` |  | no | Marks the field required. |
| class | `string` |  | no | Extra classes on the select element. |
| ...rest | `attributes` |  | no | Any other select attribute: disabled, aria-invalid, aria-describedby. |

## Accessibility
- The chevron is aria-hidden and ignores the pointer, so the whole box opens the native picker and screen readers announce a plain select.
- Options use the popover colors so the native list is dark on Windows.
- The placeholder option is disabled with an empty value, so a required select cannot be submitted without a real choice.
- The component renders no label; pair it with Field or a label whose for matches the id.
- Key Arrow Up / Arrow Down: Changes the selected option
- Key Alt + Arrow Down or Space: Opens the option list
- Key Type a letter: Jumps to the next option starting with it

## Agent prompts

### Install and use

Install the Haze UI component "Select" with `npx shadcn@latest add @haze/select`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Select from "@/components/haze/ui/select.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/select.md

### Customize with real content

Adapt the Haze select ui for our product. Replace the demo values of these props with our real content: id, name, options, value, placeholder, required, class, ...rest. Keep the layout, the heading level rules and these accessibility details: The chevron is aria-hidden and ignores the pointer, so the whole box opens the native picker and screen readers announce a plain select. Options use the popover colors so the native list is dark on Windows. The placeholder option is disabled with an empty value, so a required select cannot be submitted without a real choice. The component renders no label; pair it with Field or a label whose for matches the id. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using select, check it fits: use it when choosing one value from a list of roughly 4 to 15 fixed options; region, country, time zone or billing cycle pickers in forms; mobile-first forms where the operating system's own picker is the best experience. Avoid it when two or three options that fit on screen; use radio-group or toggle-group; options that need icons, search or rich content. Alternatives: @haze/radio-group, @haze/toggle-group, @haze/dropdown-menu.

## Example requests that should lead here
- Add a region select with a placeholder to the project form
- Make a billing cycle select with yearly preselected

## Source

```astro
---
import { ChevronDown } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Option {
  value: string;
  label: string;
  disabled?: boolean;
}

interface Props {
  id: string;
  name?: string;
  options: Option[];
  /** The selected value. */
  value?: string;
  /** Renders a disabled, empty first option that shows until the user chooses. */
  placeholder?: string;
  required?: boolean;
  class?: string;
  /** Any other select attribute, for example disabled, aria-describedby or aria-invalid. */
  [key: string]: unknown;
}

const { id, name = id, options, value, placeholder, required, class: className, ...rest } = Astro.props;
---

<div class={cn("relative h-10 w-full min-w-0 rounded-lg", className)}>
  <select
    id={id}
    name={name}
    required={required}
    class={cn(
      "peer h-full w-full min-w-0 appearance-none rounded-[inherit] [&::picker-icon]:hidden border border-frame bg-field pr-9 pl-3 text-[0.8125rem] tracking-[-0.01em] text-foreground",
      "transition-[border-color,background-color,box-shadow] duration-150 ease-snappy hover:border-frame-strong hover:bg-accent",
      "focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden",
      "disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:border-frame disabled:hover:bg-field aria-invalid:border-destructive! aria-invalid:focus-visible:ring-destructive/24",
      "[&>option]:bg-popover [&>option]:text-popover-foreground",
    )}
    {...rest}
  >
    {placeholder && <option value="" disabled selected={!value}>{placeholder}</option>}
    {options.map((option) => <option value={option.value} disabled={option.disabled} selected={option.value === value}>{option.label}</option>)}
  </select>
  <ChevronDown class="pointer-events-none absolute top-1/2 right-3 size-4 -translate-y-1/2 text-muted-foreground peer-disabled:opacity-50" aria-hidden="true" />
</div>
```
