Select
A button that opens a list of choices and shows the one you picked. Use it for forms, filters, pagination, and compact toolbars. The chosen item lines up over the trigger, arrow keys move through the list, and typing jumps to a match.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/select.jsonCopies Select and the components it uses (Field) into your app, installs the packages, and adds the styles. Then import it from @/components/ui/select. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @base-ui/react @hugeicons/core-free-icons @hugeicons/reactAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Add the components it uses: Field.
Copy and paste the following code into your project.
'use client'; import { Select as SelectPrimitive } from '@base-ui/react/select'; import { CheckIcon } from '@/lib/sprout/icons/check-icon'; import { ChevronDownIcon } from '@/lib/sprout/icons/chevron-down-icon'; import { ChevronUpIcon } from '@/lib/sprout/icons/chevron-up-icon'; import { cn, stateClassName } from '@/lib/sprout/classes'; import { useFieldControl } from '@/components/ui/field'; export const selectTriggerSizeNames = ['md', 'sm', 'lg'] as const; export const selectTriggerWidthNames = ['fit', 'full'] as const; export type SelectTriggerSize = (typeof selectTriggerSizeNames)[number]; export type SelectTriggerWidth = (typeof selectTriggerWidthNames)[number]; export type SelectProps<Value = unknown, Multiple extends boolean | undefined = false> = SelectPrimitive.Root.Props< Value, Multiple >; export const Select = SelectPrimitive.Root; export type SelectGroupProps = SelectPrimitive.Group.Props; export function SelectGroup({ className, ...props }: SelectGroupProps) { return ( <SelectPrimitive.Group data-slot="select-group" {...props} className={stateClassName<SelectPrimitive.Group.State>('sprout-select-group', className)} /> ); } export type SelectValueProps = SelectPrimitive.Value.Props; export function SelectValue({ className, ...props }: SelectValueProps) { return ( <SelectPrimitive.Value data-slot="select-value" {...props} className={stateClassName<SelectPrimitive.Value.State>('sprout-select-value', className)} /> ); } export interface SelectTriggerProps extends SelectPrimitive.Trigger.Props { size?: SelectTriggerSize; width?: SelectTriggerWidth; } export function SelectTrigger({ className, size = 'md', width = 'fit', children, ...rest }: SelectTriggerProps) { const props = useFieldControl(rest); return ( <SelectPrimitive.Trigger data-slot="select-trigger" data-size={size} data-width={width} {...props} className={stateClassName<SelectPrimitive.Trigger.State>( cn('sprout-select-trigger', `sprout-select-trigger-${size}`, `sprout-select-trigger-${width}`), className, )} > {children} <SelectPrimitive.Icon className="sprout-select-icon"> <ChevronDownIcon aria-hidden="true" /> </SelectPrimitive.Icon> </SelectPrimitive.Trigger> ); } type PositionerProps = Pick< SelectPrimitive.Positioner.Props, | 'align' | 'alignOffset' | 'side' | 'sideOffset' | 'alignItemWithTrigger' | 'collisionPadding' | 'collisionAvoidance' | 'sticky' | 'positionMethod' >; export interface SelectContentProps extends SelectPrimitive.Popup.Props, PositionerProps { container?: SelectPrimitive.Portal.Props['container']; } export function SelectContent({ side = 'bottom', sideOffset = 4, align = 'center', alignOffset = 0, alignItemWithTrigger = true, collisionPadding = 8, collisionAvoidance, sticky, positionMethod, container, className, children, ...props }: SelectContentProps) { return ( <SelectPrimitive.Portal container={container}> <SelectPrimitive.Positioner className="sprout-select-positioner" side={side} sideOffset={sideOffset} align={align} alignOffset={alignOffset} alignItemWithTrigger={alignItemWithTrigger} collisionPadding={collisionPadding} collisionAvoidance={collisionAvoidance} sticky={sticky} positionMethod={positionMethod} > <SelectPrimitive.Popup data-slot="select-content" data-align-trigger={alignItemWithTrigger} {...props} className={stateClassName<SelectPrimitive.Popup.State>('sprout-select-content', className)} > <SelectScrollUpButton /> <SelectPrimitive.List className="sprout-select-list">{children}</SelectPrimitive.List> <SelectScrollDownButton /> </SelectPrimitive.Popup> </SelectPrimitive.Positioner> </SelectPrimitive.Portal> ); } export type SelectLabelProps = SelectPrimitive.GroupLabel.Props; export function SelectLabel({ className, ...props }: SelectLabelProps) { return ( <SelectPrimitive.GroupLabel data-slot="select-label" {...props} className={stateClassName<SelectPrimitive.GroupLabel.State>('sprout-select-label', className)} /> ); } export type SelectItemProps = SelectPrimitive.Item.Props; export function SelectItem({ className, children, ...props }: SelectItemProps) { return ( <SelectPrimitive.Item data-slot="select-item" {...props} className={stateClassName<SelectPrimitive.Item.State>('sprout-select-item', className)} > <SelectPrimitive.ItemText className="sprout-select-item-text">{children}</SelectPrimitive.ItemText> <SelectPrimitive.ItemIndicator className="sprout-select-item-indicator"> <CheckIcon aria-hidden="true" /> </SelectPrimitive.ItemIndicator> </SelectPrimitive.Item> ); } export type SelectSeparatorProps = SelectPrimitive.Separator.Props; export function SelectSeparator({ className, ...props }: SelectSeparatorProps) { return ( <SelectPrimitive.Separator data-slot="select-separator" {...props} className={stateClassName<SelectPrimitive.Separator.State>('sprout-select-separator', className)} /> ); } export type SelectScrollUpButtonProps = SelectPrimitive.ScrollUpArrow.Props; export function SelectScrollUpButton({ className, ...props }: SelectScrollUpButtonProps) { return ( <SelectPrimitive.ScrollUpArrow data-slot="select-scroll-up-button" {...props} className={stateClassName<SelectPrimitive.ScrollUpArrow.State>( 'sprout-select-scroll-button sprout-select-scroll-up', className, )} > <ChevronUpIcon aria-hidden="true" /> </SelectPrimitive.ScrollUpArrow> ); } export type SelectScrollDownButtonProps = SelectPrimitive.ScrollDownArrow.Props; export function SelectScrollDownButton({ className, ...props }: SelectScrollDownButtonProps) { return ( <SelectPrimitive.ScrollDownArrow data-slot="select-scroll-down-button" {...props} className={stateClassName<SelectPrimitive.ScrollDownArrow.State>( 'sprout-select-scroll-button sprout-select-scroll-down', className, )} > <ChevronDownIcon aria-hidden="true" /> </SelectPrimitive.ScrollDownArrow> ); }And the files it imports:
lib/sprout/icons/check-icon.tsxlib/sprout/icons/chevron-down-icon.tsxlib/sprout/icons/chevron-up-icon.tsxlib/sprout/icons/create-icon.tsx
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-select-trigger { --sprout-select-icon: 1rem; box-sizing: border-box; min-width: 0; max-width: 100%; height: var(--sprout-control-height); border: 1px solid var(--sprout-input); border-radius: var(--sprout-radius-control); background: var(--sprout-surface); color: var(--sprout-text); box-shadow: var(--sprout-shadow-control); font-family: inherit; font-size: var(--sprout-text-sm); text-align: start; white-space: nowrap; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; outline: none; justify-content: space-between; align-items: center; gap: 6px; padding: 0 8px 0 10px; font-weight: 400; line-height: 20px; display: inline-flex; } @media (hover: hover) { .sprout-select-trigger:hover { border-color: var(--sprout-border); } } .sprout-select-trigger[data-popup-open] { border-color: var(--sprout-border); background: var(--sprout-hover); } .sprout-select-trigger:focus-visible { outline: var(--sprout-focus-width) solid var(--sprout-focus-ring); outline-offset: 0; } .sprout-select-trigger[data-placeholder] { color: var(--sprout-muted); } .sprout-select-trigger:disabled, .sprout-select-trigger[data-disabled] { opacity: .5; cursor: not-allowed; pointer-events: none; } .sprout-select-trigger[aria-busy="true"] { cursor: progress; } .sprout-select-trigger[aria-invalid="true"], .sprout-select-trigger[data-invalid] { border-color: var(--sprout-danger); } .sprout-select-trigger[aria-invalid="true"]:focus-visible, .sprout-select-trigger[data-invalid]:focus-visible { outline-color: var(--sprout-danger); } .sprout-select-trigger svg { pointer-events: none; flex-shrink: 0; } .sprout-select-trigger svg:not([class*="size-"]) { width: var(--sprout-select-icon); height: var(--sprout-select-icon); } .sprout-select-trigger-sm { --sprout-select-icon: .875rem; height: calc(var(--sprout-control-height) - 4px); border-radius: min(var(--sprout-radius-control), 12px); font-size: var(--sprout-text-xs); gap: 4px; padding: 0 6px 0 8px; line-height: 16px; } .sprout-select-trigger-lg { height: calc(var(--sprout-control-height) + 4px); padding: 0 10px 0 12px; } .sprout-select-trigger-fit { width: fit-content; } .sprout-select-trigger-full { width: 100%; } .sprout-select-value { text-overflow: ellipsis; white-space: nowrap; flex: auto; align-items: center; gap: 8px; min-width: 0; display: flex; overflow: hidden; } .sprout-select-value > * { min-width: 0; } .sprout-select-icon { color: var(--sprout-muted); flex-shrink: 0; display: flex; } .sprout-select-positioner { z-index: 50; isolation: isolate; outline: none; } .sprout-select-content { box-sizing: border-box; width: var(--anchor-width); min-width: 9rem; max-width: var(--available-width); max-height: var(--available-height); overscroll-behavior: contain; border: 1px solid var(--sprout-line); border-radius: var(--sprout-radius-panel); background: var(--sprout-popover); color: var(--sprout-text); box-shadow: var(--sprout-shadow-overlay); font-family: var(--sprout-font); font-size: var(--sprout-text-sm); scrollbar-width: thin; transform-origin: var(--transform-origin); outline: none; line-height: 1.25rem; position: relative; overflow: hidden auto; } .sprout-select-list { outline: none; padding: 4px; } .sprout-select-group { scroll-margin-block: 4px; } .sprout-select-label { color: var(--sprout-muted); font-size: var(--sprout-text-xs); overflow-wrap: break-word; padding: 4px 6px; font-weight: 500; line-height: 1rem; } .sprout-select-item { box-sizing: border-box; min-width: 0; min-height: calc(var(--sprout-control-height) - 4px); border-radius: var(--sprout-radius-control); color: var(--sprout-text); text-align: start; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; outline: none; align-items: center; gap: 6px; padding: 4px 32px 4px 6px; scroll-margin-block: 4px; display: flex; position: relative; } .sprout-select-item[data-highlighted] { background: var(--sprout-hover); } .sprout-select-item[data-selected] { font-weight: 500; } .sprout-select-item[data-disabled] { opacity: .5; cursor: not-allowed; } .sprout-select-item svg { pointer-events: none; flex-shrink: 0; } .sprout-select-item svg:not([class*="size-"]) { width: 16px; height: 16px; } .sprout-select-item-text { overflow-wrap: anywhere; white-space: normal; flex: auto; align-items: center; gap: 6px; min-width: 0; display: flex; } .sprout-select-item-text > svg { color: var(--sprout-muted); } .sprout-select-item-indicator { pointer-events: none; justify-content: center; align-items: center; display: flex; position: absolute; inset-inline-end: 8px; } .sprout-select-separator { background: var(--sprout-line); pointer-events: none; height: 1px; margin: 4px -4px; } .sprout-select-scroll-button { z-index: 1; background: var(--sprout-surface); width: 100%; height: 24px; color: var(--sprout-muted); cursor: default; justify-content: center; align-items: center; display: flex; } .sprout-select-scroll-up { border-radius: var(--sprout-radius-panel) var(--sprout-radius-panel) 0 0; top: 0; } .sprout-select-scroll-down { border-radius: 0 0 var(--sprout-radius-panel) var(--sprout-radius-panel); bottom: 0; } .sprout-select-scroll-button svg { width: 14px; height: 14px; } @media (pointer: coarse) { .sprout-select-trigger, .sprout-select-item { min-height: 2.75rem; } } @media (forced-colors: active) { .sprout-select-item[data-highlighted] { outline-offset: -1px; outline: 2px solid highlight; } } @media (prefers-reduced-motion: no-preference) { .sprout-select-trigger { transition: background-color var(--sprout-motion-fast) ease-out, border-color var(--sprout-motion-fast) ease-out, opacity var(--sprout-motion-fast) ease-out; } .sprout-select-content { transition: opacity var(--sprout-motion-fast) var(--sprout-motion-ease), scale var(--sprout-motion-fast) var(--sprout-motion-ease); } .sprout-select-content[data-starting-style], .sprout-select-content[data-ending-style] { opacity: 0; scale: .96; } .sprout-select-content[data-side="none"][data-starting-style], .sprout-select-content[data-side="none"][data-ending-style] { scale: 1; } .sprout-select-item { transition: background-color var(--sprout-motion-fast) ease-out; } } }Import it from
@/components/ui/select. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/select.
[email protected] · 30 minutes · Does not repeat · America/Los_Angeles
Usage
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@tulipfarm/sprout/select";
const durations = [
{ value: "30", label: "30 minutes" },
{ value: "60", label: "1 hour" },
{ value: "90", label: "90 minutes" },
];
<label htmlFor="event-duration">Duration</label>
<Select items={durations} value={duration} onValueChange={setDuration}>
<SelectTrigger id="event-duration" width="full">
<SelectValue />
</SelectTrigger>
<SelectContent>
{durations.map((item) => (
<SelectItem key={item.value} value={item.value}>
{item.label}
</SelectItem>
))}
</SelectContent>
</Select>Pass items (an array of { value, label } or a record) so SelectValue can show the label for the stored value. Name the trigger with a label htmlFor or with aria-label.
Sizes and widths
size="md" (32px) is for forms and access rows. size="sm" (28px, small text) is for pagination, filters, and docks. size="lg" (36px) is for sign-in and onboarding. width="full"fills the field; width="fit" (the default) sizes to the value. On touch screens every trigger and item is at least 44px tall.
Values and placeholders
An empty string is a real value, so “Any type” or “Workspace default” can be chosen. Use placeholder when the value is null. Children on SelectValue replace the label, for example a name looked up from an id. Values can be numbers too, as in the rows-per-page control above.
Empty string is a real value: “Any type”.
Children map the stored id to a name.
Groups and separators
Wrap related items in SelectGroup with a SelectLabel. Use SelectSeparator to set apart an item, like one that is not available on this plan.
Icons and rich items
Items can hold an icon or two lines of text. Long text wraps in the list and is cut off with an ellipsis in the trigger. Disabled items can be reached with arrow keys but can’t be chosen.
Channels already posting here are disabled.
Leave empty to let the workspace choose.
States
Set disabled on Select while a list loads, while work runs, or when it is empty, and add aria-busy to the trigger while loading. Set aria-invalid and point aria-describedby at the error. With required and name, the value is sent with the form, the form won’t submit without it, and a disabled fieldset disables the select.
Locked while the workflow is running.
Loading tables…
No tables yet. Create one in Tables first.
Saving fallback…
Choose a source to continue.
In toolbars and overlays
Small selects sit in filter bars and inline in a sentence. Lists open above popovers and sheets. A trigger can be passed to TooltipTrigger through render.
<Select value={mode} onValueChange={setMode}>
<Tooltip>
<TooltipTrigger render={<SelectTrigger size="sm" aria-label="Chat mode" />}>
<SelectValue>{mode === "plan" ? "Plan" : "Normal"}</SelectValue>
</TooltipTrigger>
<TooltipContent>
Normal acts on your request. Plan only proposes steps first.
</TooltipContent>
</Tooltip>
<SelectContent>
<SelectItem value="normal">Normal</SelectItem>
<SelectItem value="plan">Plan only</SelectItem>
</SelectContent>
</Select>API
Select is the Base UI select root. It takes value, defaultValue, onValueChange, items, disabled, required, name, and every other root prop.
SelectTrigger takes size ("default","sm", or "calendar") and width ("fit" or "full"), plus id, aria-*, andrender. It passes through field props such as aria-invalid, aria-required, and aria-describedby.
SelectContent renders its own portal, positioner, list, and scroll arrows. It takes side (bottom), align(center), sideOffset (4), alignOffset (0), alignItemWithTrigger (true), collisionPadding (8), and container.
SelectValue, SelectItem, SelectGroup, SelectLabel, SelectSeparator, SelectScrollUpButton, and SelectScrollDownButton wrap the Base UI parts and take their props. Every part sets a data-slot.
Accessibility
The trigger is a combobox with aria-expanded. Enter, Space, and the arrow keys open the list. Arrow keys move, Home and End jump, typing finds a match, Enter picks, and Escape closes and returns focus to the trigger. The chosen item shows a check mark.
The list fades and scales in over 120ms, and only fades when it lines up over the trigger. Motion turns off when reduced motion is requested. In forced-colors mode the highlighted item gets an outline.
Theme tokens
Selects use --sprout-surface, --sprout-input, --sprout-border, --sprout-line, --sprout-hover, --sprout-text, --sprout-muted, --sprout-focus, --sprout-danger, --sprout-shadow-control, --sprout-shadow-overlay, and the control and panel radii. Only the focus ring follows the brand, so they look right with the neutral and TulipFarm themes in light and dark mode.