Skip to content
Browse documentation

A choice from a list that is never the browser's dropdown: the pill grows into its list and folds back as the label morphs.

Used forFormsTable toolbarsSettingsMapping screens

Install with the shadcn CLI

$ npx shadcn@latest add @hairline/select

Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/select.json. More

Used in a block

All blocks

Templates

Need the whole page?

65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.

Where it’s used

  • Forms

    Country, role or timezone with a label and hint.

  • Table toolbars

    Sort by and rows per page.

  • Settings

    Language and theme choices.

  • Mapping screens

    Picking a field for each column.

What it handles for you

A styled select has to handle typeahead, scrolling lists, collision with the viewport and clipping parents. This one does all four.

Instead of wiring upRadix Selectnative <select>portal and collision logic
  1. One surface

    The pill grows into the list and folds back; nothing pops over it.

  2. Typeahead

    Typing a few letters finds an option; arrows glide a highlight.

  3. Never clipped

    A portal on the body that carries the theme tokens with it.

  4. Field like the rest

    Label, hint and error from field.tsx.

Overview

Native selects ignore the theme and look different on every system; most custom ones pop a panel over the trigger. Here the pill itself grows into the list from the edge it lines up with, opens upward when there is no room, and folds back as its label morphs to the choice. It lives in a portal, so no card or scroller clips it.

States

closed
A pill with the chosen label and a chevron.
open
The pill grows into its list (420ms, size and corners), upward if there is no room.
pick
The list folds back and the label morphs; the chosen option carries a drawn check.

Usage

usage.tsx
import { Select } from "@/components/select";<Select label="Timezone" defaultValue="europe-london" options={[  { value: "europe-london", label: "London" },  { value: "america-new-york", label: "New York" },]} />

Works with

Props

options
{ value, label, description? }[]
The list.
value / defaultValue
string | null
Chosen value.
onValueChange
(value: string) => void
Called on choice.
label
string
Shown above; accessible name.
hideLabel= false
boolean
Keep the name, hide the text.
hint / error
ReactNode
As in Input.
placeholder / align / width / mono
…
Passed to the pill.

Accessibility and motion

  • Escape folds it back; scrolling the page closes it.
  • Reduced motion: it opens and closes in place.

Requirements

React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

The CLI also installs Text morph.

Source

"use client";import * as React from "react";import { Field, useFieldIds } from "./field";import { PillSelect, type PillOption, type PillSelectProps } from "./pill-select";/* ───────────────────────────────────────────────────────── * SELECT: a choice from a list, never the browser's dropdown * *   open     the pill grows into its list (size and corners ease) *            from the edge it lines up with; upward when there's *            no room below; long lists scroll *   pick     the list folds back into the pill and the label *            morphs to the choice, which carries a drawn check *   keys     arrows glide a highlight, typing finds an option, *            Enter picks, Escape folds it back * * The list lives in a portal, so no toolbar, card or scroller * clips it. Labelled and hinted like every other field. * ───────────────────────────────────────────────────────── */export type SelectOption = PillOption;export interface SelectProps extends Omit<PillSelectProps, "label" | "value" | "onValueChange"> {  /** Shown above; also the accessible name. */  label: string;  /** Hide the label visually (it stays the accessible name). */  hideLabel?: boolean;  hint?: React.ReactNode;  error?: React.ReactNode;  value?: string | null;  defaultValue?: string | null;  onValueChange?: (value: string) => void;  id?: string;}export function Select({ label, hideLabel, hint, error, value, defaultValue = null, onValueChange, id, className = "", block = true, size = "md", ...props }: SelectProps) {  const ids = useFieldIds(id);  const [own, setOwn] = React.useState<string | null>(defaultValue);  const current = value !== undefined ? value : own;  return (    <Field id={ids.id} label={hideLabel ? undefined : label} hint={hint} error={error} className={className}>      <PillSelect        {...props}        block={block}        size={size}        label={label}        value={current}        onValueChange={(v) => {          if (value === undefined) setOwn(v);          onValueChange?.(v);        }}      />    </Field>  );}export default Select;

Registry item: /r/select.json