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
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.
<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.
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.
<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.
<Select variant="outline" ariaLabel="Category" defaultValue="utilities" options={CATEGORIES} />
<Select variant="soft" ariaLabel="Category" defaultValue="utilities" options={CATEGORIES} />Disabled
<Select ariaLabel="Category" defaultValue="rent" options={CATEGORIES} disabled />Long lists
The list scrolls inside the available viewport height, with scroll buttons at the ends.
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.
<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
| Select | Dropdown | Combobox | |
|---|---|---|---|
| Best for | Picking one value from a styled list, with groups or leading icons | Compact pickers and filters; the native variant for the OS picker on phones | Long lists people search by typing, or values that may not be in the list |
| Popup | Custom listbox (Radix Select) | Custom listbox by default; variant="native" renders a real <select> | Text input with a filtered list |
| Free text | No | No | Yes, any typed string is the value |
| Options | { value, label, prefix? } or groups | { value, label } | Strings |
| Sizes | sm, md, lg | sm, md | sm, md |
| Empty state | Shows placeholder until something is picked | Starts on the first option | Shows 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
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | — | Active selected option value (controlled). Omit and use `defaultValue` for uncontrolled. |
| defaultValue | string | — | 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. |
| ariaLabel | string | — | Accessible ARIA label string. |
| placeholder | string | — | Placeholder text when value is unselected. |
| className | string | — | Optional custom CSS class name for the trigger. |
| contentClassName | string | — | Optional custom CSS class name for the portaled dropdown content. |
| contentStyle | React.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. |
| disabled | boolean | — | Whether the control is disabled. |
| id | string | — | id of the trigger, so a `<label htmlFor>` can name it. |
| name | string | — | Form field name; submits the value through Radix's hidden native select. |
| required | boolean | — | Marks the field required for forms and assistive tech. |
* required