Select

A dropdown select control with multiple size variants.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/select.json

Usage

import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@/components/ui/select"

Examples

Default

One choice from a short, fixed list. The placeholder belongs to SelectValue, not the trigger, and Field ties the label to the trigger, so there is no id to write.

Trailing value

trailing puts a short value, such as a count, on a row's right edge. The check moves to the left edge so the right side is free. The trigger shows only the label.

Trigger sized to its value

A w-auto trigger is as wide as its value, and the menu grows to its longest row, so longer options stay on one line. Side text such as a tag goes in trailing, never in the label.

API Reference

PropTypeDefaultDescription
sizeSelectTrigger"xs" | "sm" | "default""default"Trigger height and text size.
positionSelectContent"item-aligned" | "popper""popper"Dropdown positioning strategy: item-aligned overlays the trigger like a native select, popper anchors against it like a popover.
alignSelectContent"start" | "center" | "end""center"Alignment against the trigger along the chosen side; only applies when position is popper.
value*SelectItemstringNoneThe value submitted when the item is selected.
defaultValueSelectstringNoneThe initially selected value for uncontrolled usage.
onValueChangeSelect(value: string) => voidNoneCalled with the new value when the selection changes. Pair with value for controlled usage.
disabledSelectbooleanfalseDisables the entire select.
disabledSelectItembooleanfalseDisables a single option.
trailingSelectItemReact.ReactNodeNoneA short value at the row's right edge, such as a count. Moves the check to the left edge. Not part of the label, so the trigger and typeahead ignore it.
sizeSelectTrigger"xs" | "sm" | "default" = "default"Trigger height and text size.
positionSelectContent"item-aligned" | "popper" = "popper"Dropdown positioning strategy: item-aligned overlays the trigger like a native select, popper anchors against it like a popover.
alignSelectContent"start" | "center" | "end" = "center"Alignment against the trigger along the chosen side; only applies when position is popper.
value*SelectItemstringThe value submitted when the item is selected.
defaultValueSelectstringThe initially selected value for uncontrolled usage.
onValueChangeSelect(value: string) => voidCalled with the new value when the selection changes. Pair with value for controlled usage.
disabledSelectboolean = falseDisables the entire select.
disabledSelectItemboolean = falseDisables a single option.
trailingSelectItemReact.ReactNodeA short value at the row's right edge, such as a count. Moves the check to the left edge. Not part of the label, so the trigger and typeahead ignore it.