Skip to content
Klarhimmel UI

Select

npx shadcn add @klarhimmel/select @klarhimmel/input

Examples

  • 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

Nothing chosen yet.

select.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Field } from '@/components/klarhimmel/ui/input';
import { Select } from '@/components/klarhimmel/ui/select';

export default function Example() {
  return (
    <Theme theme="brand">
      <Field label="Room">
        {(p) => (
          <Select
            {...p}
            options={[
              { value: 'sea', label: 'Seaside suite' },
              { value: 'garden', label: 'Garden room' },
              { value: 'loft', label: 'Loft' },
            ]}
            placeholder="Choose a room"
          />
        )}
      </Field>
    </Theme>
  );
}

Import

Import

import { Select } from '@/components/klarhimmel/ui/select';
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

PropTypeDefaultDescription
optionsSelectOption[]requiredRequired.
valuestring-Controlled or uncontrolled state.
defaultValuestring-Controlled or uncontrolled state.
onValueChange(value: string) => void-Controlled or uncontrolled state.
placeholderstring'Choose…'Shown while nothing is chosen.
namestring-Submits the value with a form.
idstring-
disabledboolean-Error styling; switches it off.
invalidboolean-Error styling; switches it off.
aria-labelstring-Needed when no <label htmlFor> or Field names it.
aria-labelledbystring-Needed when no Field or <label htmlFor> names it.
aria-describedbystring-
classNamestring-Extra classes, merged after the component's own.

Accessibility

KeyDoes
Enter / Space / Down / UpOpens the list on the chosen option
Down / UpMoves the highlight (stops at the ends)
Home / EndFirst or last option
Page Down / Page UpTen options at a time
LettersJump to the option that starts with them; repeat a letter to cycle
Enter / SpaceChooses the highlighted option and closes
Alt+UpChooses and closes
TabChooses the highlighted option and moves on
EscapeCloses 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