Components

Select

Accessible dropdown select built on Base UI Select primitives.

Category: Form / Base UI Overlay

Dependency: @base-ui-components/react

Import

import {
  Select,
  SelectGroup,
  SelectValue,
  SelectTrigger,
  SelectContent,
  SelectLabel,
  SelectItem,
  SelectSeparator,
} from "@hareru/ui"

Exports

NameTypeDescription
SelectComponentRoot component (Base UI Select.Root)
SelectGroupComponentGroups related items (Base UI Select.Group)
SelectValueComponentDisplays the selected value or placeholder
SelectTriggerComponentButton that opens the dropdown
SelectContentComponentDropdown panel rendered in a portal
SelectLabelComponentGroup heading label
SelectItemComponentIndividual selectable option
SelectSeparatorComponentVisual divider between groups

Types

export interface SelectValueProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, "children"> {
  placeholder?: string
  children?: React.ReactNode | ((value: unknown) => React.ReactNode)
}

export interface SelectItemProps extends React.HTMLAttributes<HTMLDivElement> {
  value?: string
  disabled?: boolean
}

Key Props

PropTypeComponentDescription
valuestringSelectControlled selected value
defaultValuestringSelectInitial uncontrolled value
onValueChange(value: string) => voidSelectCallback on selection change
disabledbooleanSelectDisables the entire select
placeholderstringSelectValueText shown when no value is selected
valuestringSelectItemThe value submitted on selection
disabledbooleanSelectItemDisables an individual option

Structure

  • SelectTrigger [trigger] (expected)
    • SelectValue [label] (expected)
  • SelectContent [content] (expected)
    • SelectGroup [container] ×N
      • SelectLabel [label]
    • SelectItem [item] (expected) ×N
    • SelectSeparator [separator] ×N

(expected) = recommended in canonical composition, not runtime-required.

Accessibility

  • Roles: listbox
  • Keyboard:
    • Arrow keys to navigate options
    • Enter to select
    • Escape to close
  • Notes: ARIA listbox pattern provided by Base UI.

Usage

import {
  Select,
  SelectGroup,
  SelectValue,
  SelectTrigger,
  SelectContent,
  SelectLabel,
  SelectItem,
  SelectSeparator,
} from "@hareru/ui"

<Select>
  <SelectTrigger>
    <SelectValue placeholder="Select an option" />
  </SelectTrigger>
  <SelectContent>
    <SelectGroup>
      <SelectLabel>Fruits</SelectLabel>
      <SelectItem value="apple">Apple</SelectItem>
      <SelectItem value="banana">Banana</SelectItem>
    </SelectGroup>
    <SelectSeparator />
    <SelectGroup>
      <SelectLabel>Vegetables</SelectLabel>
      <SelectItem value="carrot">Carrot</SelectItem>
      <SelectItem value="broccoli" disabled>Broccoli</SelectItem>
    </SelectGroup>
  </SelectContent>
</Select>

// Controlled
<Select value={value} onValueChange={setValue}>
  <SelectTrigger>
    <SelectValue placeholder="Choose..." />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="a">Option A</SelectItem>
    <SelectItem value="b">Option B</SelectItem>
  </SelectContent>
</Select>

Notes

  • SelectContent is rendered in a portal. No extra wrapper is needed.
  • The dropdown includes scroll arrows that appear automatically when items overflow.
  • Selected items display a checkmark indicator via SelectItem's built-in indicator.

On this page