Skip to Content
Getting startedFoundationsComponentsPackagesTools

Select

A trigger and a panel of options that haus draws, so an option can carry a hint.

Examples

Playground

States

Every state side by side. Hover and focus are forced, so they can be reviewed without a pointer. Open is the Motion story.

rest
hover
focus
placeholder
error
Pick a role for this member
disabled

Content

Options with a second line, which a native select cannot draw; plain options with one disabled, which the keyboard skips; and a hint under the field.

options with hints
plain options, one disabled
field hint
Who can accept a decision in this workspace

Install

npx shadcn add @hipuku/select

Usage

import { Select } from '@/components/haus/components/Select'

<Select
  label="Role"
  value={role}
  onChange={setRole}
  options={[
    { label: 'Author', value: 'author', hint: 'Can propose and revise' },
    { label: 'Viewer', value: 'viewer' },
  ]}
/>

API

Select also takes its element's own attributes and forwards its ref. className lands on the root and controlClassName on the trigger.

PropTypeDescription
optionsrequiredSelectOption[]
valuerequiredstring
onChangerequired(value: string) => void
placeholderstringShown when nothing is selected.
disabledboolean
namestringRenders a hidden input so the control still submits inside a plain <form action>. Omit it for a purely controlled use.
controlClassNamestringLands on the trigger rather than the root. Ruling B5.
hintstringA line under the control that describes it, read out with it. Stays when there is an error, which sits above it. Same as Input's.
errorstringWhat is wrong with the current choice. Marks the trigger aria-invalid, rings it in the error colour, and is announced when it appears.
portalbooleanRender the panel into document.body, for a Select inside something that clips: a Modal body is overflow-y: auto, and an absolute panel is cut off at its edge. Passed straight to Popover. haus#68.
classNamestring
labelstring

Options and forms

Options come from options. Each has a label, a value, and an optional hint shown under the label, which a native <select> cannot do, and disabled. Select is controlled: pass value and onChange. Set name and it submits inside a plain form.

Inside something that scrolls or clips, such as a Modal's body, set portal so the panel is not cut off.

Accessibility

  • A name is required, as label or aria-labelledby.
  • Focus stays on the trigger. The arrow keys move the highlight, Enter or Space chooses, and typing a letter jumps to the next option starting with it.
  • Escape or a click outside closes it. The selected option carries a check, not only a colour.

On this page