Select
- Seaside suite
- Garden room
- Loft
npx shadcn add @klarhimmel/select @klarhimmel/inputCopy for AIExamples
Basic
States
Form
DetailsAbout, usage, props and more
A custom dropdown with a keyboard-complete listbox, type-ahead and form value.
When to use
Use for
Choosing one of five to fifty options, with search by typing the first letters.
Not for
Two to five options. Use Radio group. Long lists people can name. Use Combobox.
Pairs with
Field, forms.
Preview
- Seaside suite
- Garden room
- Loft
- Barn cottage
- Attic room
Nothing chosen yet.
Import
Import
- Files
- select.tsx, input.tsx, in components/klarhimmel/ui/. With it: button, editing, theme, utils. npm: lucide-react.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | SelectOption[] | required | Required. |
value | string | - | Controlled or uncontrolled state. |
defaultValue | string | - | Controlled or uncontrolled state. |
onValueChange | (value: string) => void | - | Controlled or uncontrolled state. |
placeholder | string | 'Choose…' | Shown while nothing is chosen. |
name | string | - | Submits the value with a form. |
id | string | - | |
disabled | boolean | - | Error styling; switches it off. |
invalid | boolean | - | Error styling; switches it off. |
aria-label | string | - | Needed when no <label htmlFor> or Field names it. |
aria-labelledby | string | - | Needed when no Field or <label htmlFor> names it. |
aria-describedby | string | - | |
className | string | - | Extra classes, merged after the component's own. |
Accessibility
| Key | Does |
|---|---|
Enter / Space / Down / Up | Opens the list on the chosen option |
Down / Up | Moves the highlight (stops at the ends) |
Home / End | First or last option |
Page Down / Page Up | Ten options at a time |
Letters | Jump to the option that starts with them; repeat a letter to cycle |
Enter / Space | Chooses the highlighted option and closes |
Alt+Up | Chooses and closes |
Tab | Chooses the highlighted option and moves on |
Escape | Closes without changing |
ARIA select-only combobox. A click outside only closes the list; Tab commits the highlighted option. Inside a small scrolling panel prefer NativeSelect.
Accessibility