When to use
- Picking from a fixed set of up to about 15 options: a region, a timezone, a member's role.
- Settings forms where the value should read like text in a field, not like a button.
- A same-width control per row of a list (a role column), so every row lines up (R102).
When not to use
- Long lists, or lists people search: use Combobox.
- Two to four options that should all stay visible: use Segmented or Radio Group.
- Actions rather than values: use a Dropdown Menu.
Installation
pnpm dlx shadcn add https://eased.dev/r/select.jsonnpx shadcn add https://eased.dev/r/select.jsonyarn dlx shadcn add https://eased.dev/r/select.jsonbunx --bun shadcn add https://eased.dev/r/select.jsonThe command adds Select, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add @base-ui/react motionnpm install @base-ui/react motionyarn add @base-ui/react motionbun add @base-ui/react motionAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/select/select.tsxTSX "use client";import { Select as BaseSelect } from "@base-ui/react/select";import { motion, type HTMLMotionProps } from "motion/react";import { Fragment, useLayoutEffect, useRef, useState, type ReactNode, type RefObject } from "react";import { InputGroup, type ControlSize } from "../_primitives/field/field";import { FloatingLayer } from "../_primitives/floating/floating";import { groupClass, groupLabelClass, HighlightGroup, itemClass, ItemCheck, ItemParts, OVERLAY_ROLES, panelSurface, separatorClass, withHighlight,} from "../_primitives/overlay-core/overlay-core";/** * A select on Base UI's Select, in the Eased Input's bordered shell. Like a macOS pop-up * button, the list opens with the selected row sitting over the trigger and grows from that * row; when there's no room (or on touch) it drops below the trigger like a listbox instead. * The highlight glides between rows on the snappy spring. */export type SelectOption<V> = { value: V; /** The row's text, and what the trigger shows once it is chosen. */ label: string; /** A 16px glyph, flag or colour dot before the label. */ icon?: ReactNode; /** A second, muted line under the label. */ description?: ReactNode; disabled?: boolean;};export type SelectOptionGroup<V> = { /** The group's heading. */ label: string; items: SelectOption<V>[];};type RootProps<V, M extends boolean | undefined> = Omit< BaseSelect.Root.Props<V, M>, "items" | "children" | "itemToStringLabel" | "isItemEqualToValue">;export type SelectProps<V, M extends boolean | undefined = false> = RootProps<V, M> & { /** The options, flat or in groups. Leave out to compose `SelectItem` / `SelectGroup` children instead. */ items?: SelectOption<V>[] | SelectOptionGroup<V>[]; /** Rows composed by hand (`SelectItem`, `SelectGroup`, `SelectSeparator`). Ignored when `items` is set. */ children?: ReactNode; /** Muted text in the trigger while nothing is chosen. */ placeholder?: ReactNode; /** sm 32px, md 36px (default), lg 40px. */ size?: ControlSize; /** * Mark the select invalid outside a `Field` (inside one, the field's validity drives it): * red border and one shake when it turns on. */ invalid?: boolean; /** * Open with the selected row over the trigger (default true). Base UI falls back to a list * below the trigger on touch and when there isn't room; false always drops below. */ alignItemWithTrigger?: boolean; /** Format the trigger's value, e.g. to add the chosen option's icon. Default: its label. */ renderValue?: (value: M extends true ? V[] : V | null) => ReactNode; /** The trigger's accessible name when no `Field` label or `aria-labelledby` names it. */ "aria-label"?: string; "aria-labelledby"?: string; /** Portal target. Default `document.body`. */ container?: HTMLElement | null; /** Stacking order of the popup. Default 50; raise it inside a higher layer (a dialog). */ zIndex?: number; /** Classes for the bordered shell (set a width here; it fills its container by default). */ className?: string; /** Classes for the popup. */ popupClassName?: string;};// The trigger covers the shell's padding so the whole box is one button.const TRIGGER_INSET: Record<ControlSize, string> = { sm: "-mx-2.5 px-2.5", md: "-mx-3 px-3", lg: "-mx-3.5 px-3.5" };/* * The popup holds the scroll arrows (absolutely placed by Base UI), so the list inside it is the * scroller and carries the menu's three tracks (icon · label · trailing) that rows subgrid into. * In align mode the popup is wider than the trigger by the check track, so the trigger's box is * covered while the selected label sits on the trigger's value. */const POPUP = `${panelSurface} relative flex flex-col overflow-hidden min-w-(--anchor-width) max-w-(--available-width) max-h-(--available-height) data-[side=none]:min-w-[calc(var(--anchor-width)+1.75rem)]`;const LIST = "isolate grid min-h-0 flex-1 grid-cols-[auto_minmax(0,1fr)_auto] content-start overflow-y-auto overscroll-contain p-1 scroll-py-6 outline-none [--pad:4px]";const ARROW = "absolute inset-x-0 z-10 flex h-6 cursor-default items-center justify-center text-text-muted from-surface-raised from-30% to-transparent transition-opacity duration-(--eased-duration-fast) ease-standard data-starting-style:opacity-0 data-ending-style:opacity-0 reduced:transition-none before:absolute before:inset-x-0 before:h-full";/** * The select. Pass `items` for the common case, or compose rows as children: * * <Select items={regions} defaultValue="eu-west" aria-label="Region" /> */export function Select<V, M extends boolean | undefined = false>({ items, children, placeholder, size = "md", invalid, alignItemWithTrigger = true, renderValue, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, container, zIndex, className = "", popupClassName = "", disabled, ...props}: SelectProps<V, M>) { const anchor = useRef<HTMLDivElement>(null); const trigger = useRef<HTMLButtonElement>(null); const fieldInvalid = useDataInvalid(trigger); return ( <BaseSelect.Root<V, M> {...props} disabled={disabled} items={items}> <div ref={anchor} className={`flex w-full min-w-0 ${className}`}> <InputGroup size={size} invalid={invalid ?? fieldInvalid} className="has-[[data-popup-open]]:not-data-invalid:border-(--eased-neutral-9)"> <BaseSelect.Trigger ref={trigger} aria-label={ariaLabel} aria-labelledby={ariaLabelledBy} {...(invalid !== undefined ? { "aria-invalid": invalid } : null)} className={`flex min-w-0 flex-1 cursor-default items-center gap-2 self-stretch rounded-[inherit] text-start outline-none select-none disabled:cursor-not-allowed ${TRIGGER_INSET[size]}`} > <BaseSelect.Value placeholder={placeholder} className="min-w-0 flex-1 truncate data-placeholder:text-text-muted" > {renderValue as ((value: unknown) => ReactNode) | undefined} </BaseSelect.Value> <BaseSelect.Icon className="-me-0.5 inline-flex shrink-0 text-text-muted in-disabled:text-text-disabled"> <ChevronUpDownIcon /> </BaseSelect.Icon> </BaseSelect.Trigger> </InputGroup> </div> <FloatingLayer parts={BaseSelect} motion={OVERLAY_ROLES.listbox} side={OVERLAY_ROLES.listbox.side} sideOffset={OVERLAY_ROLES.listbox.sideOffset} align="start" container={container} zIndex={zIndex} positionerProps={{ alignItemWithTrigger, anchor }} className={`${POPUP} ${popupClassName}`} > <BaseSelect.ScrollUpArrow className={`${ARROW} top-0 bg-linear-to-b data-[side=none]:before:-top-full`}> <ChevronIcon up /> </BaseSelect.ScrollUpArrow> {/* The list is a Motion element with `layoutScroll`, so the gliding highlight measures rows through the list's scroll offset: it stays correct while the list scrolls under it (wheel, scroll arrows, typeahead jumps, align mode's initial scroll). A render callback, not a component, so Base UI calls it as a plain function. */} <BaseSelect.List render={(props) => <motion.div {...(props as HTMLMotionProps<"div">)} layoutScroll />} className={LIST}> <HighlightGroup>{items ? <OptionRows items={items} /> : children}</HighlightGroup> </BaseSelect.List> <BaseSelect.ScrollDownArrow className={`${ARROW} bottom-0 bg-linear-to-t data-[side=none]:before:-bottom-full`}> <ChevronIcon /> </BaseSelect.ScrollDownArrow> </FloatingLayer> </BaseSelect.Root> );}function OptionRows<V>({ items }: { items: SelectOption<V>[] | SelectOptionGroup<V>[] }) { return ( <> {items.map((entry, i) => "items" in entry ? ( <Fragment key={`group:${entry.label}`}> {i > 0 && <SelectSeparator />} <SelectGroup label={entry.label}> {entry.items.map((option) => ( <OptionRow key={String(option.value)} option={option} /> ))} </SelectGroup> </Fragment> ) : ( <OptionRow key={String(entry.value)} option={entry} /> ), )} </> );}function OptionRow<V>({ option }: { option: SelectOption<V> }) { return ( <SelectItem value={option.value} label={option.label} icon={option.icon} description={option.description} disabled={option.disabled}> {option.label} </SelectItem> );}export type SelectItemProps = { /** The value this row chooses. */ value: unknown; /** The row's text. */ children: ReactNode; /** The text typeahead matches when `children` isn't plain text. */ label?: string; /** A 16px glyph, flag or colour dot before the label. */ icon?: ReactNode; /** A second, muted line under the label. */ description?: ReactNode; disabled?: boolean;};/** * One option. The check sits in the icon track and draws in when the row is chosen; labels * share one x whether or not a row has an `icon`. */export function SelectItem({ value, children, label, icon, description, disabled }: SelectItemProps) { return ( <BaseSelect.Item value={value} label={label} disabled={disabled} className={itemClass({ glide: true })} render={withHighlight}> <ItemParts icon={ <BaseSelect.ItemIndicator keepMounted render={<span />} className="inline-flex"> <ItemCheck /> </BaseSelect.ItemIndicator> } description={description} > <span className="flex min-w-0 items-center gap-2"> {icon !== undefined && ( <span aria-hidden className="inline-flex shrink-0 [&_svg]:size-4"> {icon} </span> )} {/* The text Base UI lines up with the trigger's value in align mode. */} <BaseSelect.ItemText render={<span />} className="truncate"> {children} </BaseSelect.ItemText> </span> </ItemParts> </BaseSelect.Item> );}/** A labelled group of options that stays on the list's tracks. */export function SelectGroup({ label, children }: { label: ReactNode; children: ReactNode }) { return ( <BaseSelect.Group className={groupClass}> <BaseSelect.GroupLabel className={groupLabelClass}>{label}</BaseSelect.GroupLabel> {children} </BaseSelect.Group> );}/** A full-bleed rule between groups. */export function SelectSeparator() { return <BaseSelect.Separator className={separatorClass} />;}/** * Inside a Base UI Field the trigger carries `data-invalid`; the shell reads it from there so * it draws and shakes like an Input in the same form. */function useDataInvalid(ref: RefObject<HTMLElement | null>) { const [invalid, setInvalid] = useState(false); useLayoutEffect(() => { const el = ref.current; if (!el) return; const read = () => setInvalid(el.hasAttribute("data-invalid")); read(); const mo = new MutationObserver(read); mo.observe(el, { attributes: true, attributeFilter: ["data-invalid"] }); return () => mo.disconnect(); }, [ref]); return invalid;}function ChevronUpDownIcon() { return ( <svg viewBox="0 0 16 16" fill="none" aria-hidden className="size-4"> <path d="m5.25 6.25 2.75-2.75 2.75 2.75M5.25 9.75 8 12.5l2.75-2.75" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" /> </svg> );}function ChevronIcon({ up = false }: { up?: boolean }) { return ( <svg viewBox="0 0 16 16" fill="none" aria-hidden className={`relative size-3.5 ${up ? "rotate-180" : ""}`}> <path d="m4.5 6.5 3.5 3.5 3.5-3.5" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" /> </svg> );}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { Field } from "@/components/eased/field/field";import { Select } from "@/components/eased/select/select";const regions = [ { label: "Americas", items: [{ value: "us-east", label: "US East (Virginia)" }, { value: "us-west", label: "US West (Oregon)" }] }, { label: "Europe", items: [{ value: "eu-west", label: "EU West (Dublin)" }, { value: "eu-central", label: "EU Central (Frankfurt)" }] },];export function Example() { return ( <Field label="Data region" name="region"> <Select items={regions} defaultValue="eu-west" /> </Field> );}Examples
Composed rows
Compose rows when they need more than items describes; SelectItem takes an icon and a description.
<Select defaultValue="growth" aria-label="Plan"> <SelectItem value="starter">Starter</SelectItem> <SelectItem value="growth" description="$99 a month">Growth</SelectItem> <SelectSeparator /> <SelectGroup label="Annual"> <SelectItem value="growth-yearly">Growth, yearly</SelectItem> </SelectGroup></Select>A role column
Give every row's select the same track so roles start on one x.
<ul className={`${rowGrid} [--col:7rem]`}> <li className={rowGridRow}> <Avatar name="Jonas Lindqvist" /> <span>Jonas Lindqvist</span> <Select items={roles} size="sm" value={role} onValueChange={setRole} aria-label="Role for Jonas Lindqvist" /> </li></ul>API reference
Select
| Prop | Type | Default | Description |
|---|---|---|---|
items | SelectOption<V>[] | SelectOptionGroup<V>[] | Options, flat or grouped ({ label, items }). Groups are separated by a rule. | |
children | ReactNode | SelectItem, SelectGroup, SelectSeparator, when items is not set. | |
value / defaultValue | V | V[] | null | Controlled / uncontrolled value (an array with multiple). | |
onValueChange | (value, details) => void | ||
multiple | boolean | false | Choose several; the trigger lists them, comma-separated. |
placeholder | ReactNode | Muted text while nothing is chosen. | |
size | "sm" | "md" | "lg" | "md" | 32, 36 or 40px, like Input. |
invalid | boolean | Invalid outside a Field; inside one, the field's validity drives it. | |
disabled | boolean | false | |
name | string | Submits the value with a form. | |
alignItemWithTrigger | boolean | true | Open with the chosen row over the trigger. Base UI falls back to a list below on touch or without room. |
renderValue | (value) => ReactNode | Formats the trigger's value. | |
aria-label | string | The trigger's name when no label names it. | |
container | HTMLElement | null | document.body | Portal target. |
zIndex | number | 50 | Raise inside a higher layer. |
className | string | "" | The shell; set a width here (it fills its container). |
popupClassName | string | "" | The popup. |
SelectOption<V> is { value, label, icon?, description?, disabled? }. Every other Base UI Select.Root prop passes through (open, onOpenChange, required, readOnly, modal, form …).
SelectItem, SelectGroup, SelectSeparator
SelectItem: value, children, label (typeahead text when children aren't plain text), icon, description, disabled. SelectGroup: label, children. SelectSeparator: a full-bleed rule.
Keyboard
| Key | Action |
|---|---|
Enter / Space / ↓ / ↑ | Opens the list with the chosen row highlighted. |
↓ / ↑ / Home / End | Moves the highlight. |
| Letters | Typeahead to the next matching row. |
Enter / Space | Chooses the highlighted row and closes. |
Esc / Tab | Closes without changing the value. |
Accessibility
- The trigger is a button with
aria-haspopup="listbox"; it is named by a Field label,aria-labelledbyoraria-label. - Rows are
options in alistbox,aria-selectedon the chosen ones; group labels name their groups. - Focus moves into the list on open and returns to the trigger on close.
- Inside a Field, the trigger carries the field's description and error, and the shell turns red and shakes once when it becomes invalid.
- Rows are 40px on coarse pointers; the scroll arrows don't render on touch, where the list scrolls natively.
Motion
With the chosen row over the trigger (Base UI's data-side="none"), the popup grows from that row at 0.97 with no travel: transform-origin is the row's centre. When it falls back to a list below, it enters 4px down toward the trigger like every Eased listbox. Opacity fades in 150ms on the enter curve while scale rides the snappy spring; the exit fades in 100ms, scales half as far and never overshoots, and because both are transitions a close mid-open reverses. The highlight is one shared-layout fill that glides between rows on the snappy spring; the list is a Motion scroll container (layoutScroll), so the glide stays on target while the list scrolls under it. The check draws in on the snappy spring. Reduced motion keeps a 100ms fade and moves the highlight without travel.
Notes for AI
Pick Select for a short, fixed set of values in a form; pick Combobox when people would rather type. Pass items (flat or { label, items } groups) and defaultValue or value/onValueChange; inside a Field, label it with the Field (or FieldLabel nativeLabel={false} render={<div />}), otherwise give aria-label.
Don't wrap it in another bordered box or put it inside an Input: it is its own shell. Don't add a check, chevron, highlight or scroll handling: the rows, the glide, the scroll arrows and the align-with-trigger positioning are built in.
Related components
- Combobox and Searchable Select: the same rows with a text filter, chips for several values.
- Animated Text Input: the shell this matches.
- Animated Segmented Control: two to four options, all visible.