# Select

> A dropdown for choosing one option from a short list. The value type is generic.

Status: stable. Category: Forms.

```ts
import { Select, SelectItem } from '@glyphui/ui'
```

Exports: `Select`, `SelectItem`, `selectStyles`.

## Notes

- For long lists or search, use Combobox.

## Select props

| Prop | Type | Default | Description |
|---|---|---|---|
| `aria-describedby` | `string` |  |  |
| `aria-invalid` | `boolean` |  |  |
| `aria-label` | `string` |  |  |
| `className` | `string` |  |  |
| `contentClassName` | `string` |  |  |
| `defaultValue` | `string` |  |  |
| `id` | `string` |  |  |
| `onValueChange` | `((value: T) => void)` |  |  |
| `placeholder` | `ReactNode` |  |  |
| `size` | `"sm" \| "md" \| "lg"` |  |  |
| `value` | `string` |  |  |

## Example: In a field

```tsx
import { Field, Select, SelectItem } from '@glyphui/ui'

export default function Example() {
  return (
    <Field label="Region" className="max-w-xs">
      <Select placeholder="Choose a region" defaultValue="eu">
        <SelectItem value="us">United States</SelectItem>
        <SelectItem value="eu">Europe (Frankfurt)</SelectItem>
        <SelectItem value="ap">Asia Pacific (Tokyo)</SelectItem>
      </Select>
    </Field>
  )
}
```

## Example: Typed values

Select<Plan> only accepts and emits Plan values.

```tsx
import { Select, SelectItem, Text } from '@glyphui/ui'
import { useState } from 'react'

type Plan = 'free' | 'pro' | 'team'

export default function Example() {
  const [plan, setPlan] = useState<Plan>('pro')
  return (
    <div className="grid max-w-xs gap-2">
      <Select<Plan> value={plan} onValueChange={setPlan} aria-label="Plan">
        <SelectItem value="free">Free</SelectItem>
        <SelectItem value="pro">Pro</SelectItem>
        <SelectItem value="team">Team</SelectItem>
      </Select>
      <Text size="small" tone="muted">
        Selected: <span className="font-mono">{plan}</span>
      </Text>
    </div>
  )
}
```

Live page: https://glyphui.xyz/components/select
