Skip to content
synccn

Select

Listbox with groups, icons, typeahead and full keyboard support.

Installation

$ pnpm dlx shadcn@latest add @synccn/select

First time in this project? Connect synccn with one command.

Usage

import { Select } from "@/components/ui/select";<Select options={frameworks} placeholder="Pick one" />

API reference

Generated from the component's TypeScript types, so it always matches the code.

Select

Accessible listbox select with keyboard navigation and typeahead. options: [{ value, label, icon?, disabled?, group? }]

  • optionsrequired
    SelectOption[]

    Choices.

  • value
    string

    Controlled value.

  • defaultValue
    string

    Initial value when uncontrolled.

  • onValueChange
    (value: string) => void

    Called with the new value.

  • placeholder
    string

    Default "Select an option"

    Shown when nothing is selected.

  • disabled
    boolean

    Prevents opening.

  • aria-label
    string

    Accessible name if there's no visible label.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseAutoSide (flips to the side with room), useClickOutside (closes on an outside click), useControllable (works controlled or uncontrolled), useEscape (closes on Escape), usePresence (animates in and out)

npm packages

Keyboard

  • EnterorSpaceor↓Open the list
  • ↓or↑Move between options, skipping disabled ones
  • EnterChoose the highlighted option
  • EscorTabClose the list

Accessibility

  • The trigger has role combobox with aria-expanded and aria-controls; options use listbox and option roles.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: combobox, listbox, option, presentation
  • ARIA attributes: aria-controls, aria-disabled, aria-expanded, aria-label, aria-selected
  • Keys handled: ArrowUp, ArrowDown, Enter, Tab, Space
  • Closes with Escape
  • Closes when you click or tap outside
  • Flips to whichever side has room, so it stays on screen
  • Shows a visible focus ring for keyboard users