CraftUI

Select

Ore UI's dropdown, as a light field for forms or a dark one for filters.

Difficulty

Installation

npx shadcn@latest add @runqora/craft-select

Usage

import {
  Select,
  SelectContent,
  SelectItem,
  SelectLabel,
  SelectTrigger,
  SelectValue,
} from "@/components/craft/select";

const modes = [
  { label: "Survival", value: "survival" },
  { label: "Creative", value: "creative" },
];

<Select items={modes}>
  <SelectLabel>Game mode</SelectLabel>
  <SelectTrigger>
    <SelectValue placeholder="Choose a mode" />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="survival">Survival</SelectItem>
    <SelectItem value="creative">Creative</SelectItem>
  </SelectContent>
</Select>;

Examples

Sunken

The dark dropdown, for filters and sorting that sit in a row. Without a visible label, pass aria-label to the trigger.

Groups and disabled options

Game mode

Props

SelectTrigger

Prop

Type

SelectContent

Prop

Type

Accessibility

  • The trigger is a combobox and the list is a listbox, so screen readers announce the value and the options.
  • Space, Enter and the arrow keys open the list. The arrow keys move through it, typing jumps to a match, Enter chooses and Escape closes.
  • Disabled options are skipped. SelectLabel names the trigger.
  • The chosen option has a check as well as its highlight.

Customization

Pass items to Select so the trigger can show the chosen option's label. Without it, the trigger shows the raw value.

For a long list that people search, use Combobox.

Dependencies

Source

On this page