Skip to content

Select

Pick one value from a list. Options can be grouped, and the list stays on screen near edges.

// Radix — @radix-ui/react-select
import { Select } from "@shavin/ui";

Controlled

Component Source
import { useState } from "react";
import { Select } from "@shavin/ui";

const CATEGORIES = [
  { value: "groceries", label: "Groceries" },
  { value: "rent", label: "Rent" },
  { value: "utilities", label: "Utilities" },
  { value: "childcare", label: "Childcare" },
];

export function CategoryPicker() {
  const [category, setCategory] = useState("groceries");
  return (
    <div className="w-56">
      <Select ariaLabel="Category" value={category} onChange={setCategory} options={CATEGORIES} />
    </div>
  );
}

Uncontrolled

Pass defaultValue and leave out value. Select keeps the choice itself; onChange still fires.

Component Source
<Select ariaLabel="Category" defaultValue="rent" options={CATEGORIES} />

Groups, icons and placeholder

An option can carry a prefix node, shown in the list and in the trigger. Wrap options in { group, options } to add a group heading. The placeholder shows until a value is picked.

Component Source
import { useState } from "react";
import { Select, Icon } from "@shavin/ui";

const ACCOUNTS = [
  {
    group: "Bank accounts",
    options: [
      { value: "joint-checking", label: "Joint checking", prefix: <Icon name="Landmark" size="sm" /> },
      { value: "emergency-savings", label: "Emergency savings", prefix: <Icon name="PiggyBank" size="sm" /> },
    ],
  },
  {
    group: "Cards",
    options: [
      { value: "everyday-card", label: "Everyday card", prefix: <Icon name="CreditCard" size="sm" /> },
      { value: "travel-card", label: "Travel card", prefix: <Icon name="CreditCard" size="sm" /> },
    ],
  },
];

export function AccountPicker() {
  const [account, setAccount] = useState("");
  return (
    <div className="w-64">
      <Select
        ariaLabel="Pay from"
        placeholder="Choose an account"
        value={account}
        onChange={setAccount}
        options={ACCOUNTS}
      />
    </div>
  );
}

Sizes

Heights match Button, TextField and Combobox: sm 32px, md 40px (default), lg 48px.

Component Source
<Select size="sm" ariaLabel="Category, small" defaultValue="groceries" options={CATEGORIES} />
<Select size="md" ariaLabel="Category, medium" defaultValue="groceries" options={CATEGORIES} />
<Select size="lg" ariaLabel="Category, large" defaultValue="groceries" options={CATEGORIES} />

Variant

outline (default) has a 3:1 control border. soft is filled and borderless, for dense tool panels.

Component Source
<Select variant="outline" ariaLabel="Category" defaultValue="utilities" options={CATEGORIES} />
<Select variant="soft" ariaLabel="Category" defaultValue="utilities" options={CATEGORIES} />

Disabled

Component Source
<Select ariaLabel="Category" defaultValue="rent" options={CATEGORIES} disabled />

Long lists

The list scrolls inside the available viewport height, with scroll buttons at the ends.

Component Source
const MONTHS = ["January", "February", "March", "April", "May", "June", "July",
  "August", "September", "October", "November", "December"].map((m) => ({ value: m.toLowerCase(), label: m }));

<Select ariaLabel="Budget month" defaultValue="april" options={MONTHS} />

Labelling

Give every Select a name. With a visible label, pass id and point the label's htmlFor at it. Without one, pass ariaLabel. Use aria-describedby for hint or error text and aria-invalid to mark an error. name and required submit the value with a form.

Visible label and hint

Used for the monthly budget report.

Component Source
<div className="flex w-64 flex-col gap-1.5">
  <label htmlFor="split-category" className="text-sm font-medium text-fg">Category</label>
  <Select
    id="split-category"
    name="category"
    aria-describedby="split-category-hint"
    defaultValue="groceries"
    options={CATEGORIES}
  />
  <p id="split-category-hint" className="text-xs text-fg-subtle">Used for the monthly budget report.</p>
</div>

Select, Dropdown or Combobox

SelectDropdownCombobox
Best forPicking one value from a styled list, with groups or leading iconsCompact pickers and filters; the native variant for the OS picker on phonesLong lists people search by typing, or values that may not be in the list
PopupCustom listbox (Radix Select)Custom listbox by default; variant="native" renders a real <select>Text input with a filtered list
Free textNoNoYes, any typed string is the value
Options{ value, label, prefix? } or groups{ value, label }Strings
Sizessm, md, lgsm, mdsm, md
Empty stateShows placeholder until something is pickedStarts on the first optionShows placeholder while empty

All three support arrow keys, Enter and Escape. Select and the default Dropdown also jump to an option as you type its first letters.

Props

PropTypeDefaultDescription
valuestring—Active selected option value (controlled). Omit and use `defaultValue` for uncontrolled.
defaultValuestring—Initial selected value when uncontrolled.
options*(Option | OptionGroup)[]—Flat options list or grouped option list.
onChange(v: string) => void—Callback fired when user selects an option.
onValueChange(v: string) => void—Alias of `onChange` (Radix naming).
onItemHighlight(v: string | null) => void—Optional callback fired when an item is hovered/focused for live preview. Passed null on mouseleave/close.
ariaLabelstring—Accessible ARIA label string.
placeholderstring—Placeholder text when value is unselected.
classNamestring—Optional custom CSS class name for the trigger.
contentClassNamestring—Optional custom CSS class name for the portaled dropdown content.
contentStyleReact.CSSProperties—Optional custom inline style for the portaled dropdown content.
size"sm" | "md" | "lg"—Select trigger size. Heights match Button, TextField and Combobox: sm 32px, md 40px, lg 48px.
variant"outline" | "soft"—outline (default): a 3:1 control border (WCAG 1.4.11). soft: filled and borderless, for dense tool panels; the value and the chevron identify it. Both show the 2px focus ring.
disabledboolean—Whether the control is disabled.
idstring—id of the trigger, so a `<label htmlFor>` can name it.
namestring—Form field name; submits the value through Radix's hidden native select.
requiredboolean—Marks the field required for forms and assistive tech.

* required

Configure Theme
Theme
Brand Color
Custom
Gray Family
Appearance
Radius
Scaling
Panel Style
Heading Font
Body Font