# Select

> Accessible dropdown picker with filled and outline triggers, standard and vibrant popups, groups, and Field integration.

Canonical URL: https://taut-ui.com/docs/components/select

```tsx
import {
  Select,
  SelectItem,
  SelectPopup,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select";

const frameworks = [
  { label: "Next.js", value: "nextjs" },
  { label: "Remix", value: "remix" },
  { label: "Astro", value: "astro" },
  { label: "Nuxt", value: "nuxt" },
  { label: "SvelteKit", value: "sveltekit" },
];

export default function Particle() {
  return (
    <Select items={frameworks}>
      <SelectTrigger aria-label="Select framework" className="w-full max-w-60">
        <SelectValue placeholder="Select a framework" />
      </SelectTrigger>
      <SelectPopup>
        {frameworks.map((framework) => (
          <SelectItem key={framework.value} value={framework.value}>
            {framework.label}
          </SelectItem>
        ))}
      </SelectPopup>
    </Select>
  );
}
```

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add https://taut-ui.com/r/select.json
```

**Manual**

- Install the following dependencies:

```bash
npm install @base-ui/react class-variance-authority lucide-react
```

- Copy and paste the following code into your project.

```tsx title="components/ui/select.tsx"
"use client";

import { mergeProps } from "@base-ui/react/merge-props";
import { Select as SelectPrimitive } from "@base-ui/react/select";
import { useRender } from "@base-ui/react/use-render";
import type { VariantProps } from "class-variance-authority";
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
import type * as React from "react";
import { cn } from "@/lib/utils";
import { inputVariants } from "@/components/ui/input";
import { menuPopupVariants } from "@/components/ui/menu";

const selectIconClassName =
  "inline-flex in-data-[size=lg]:size-10 in-data-[size=sm]:size-7 size-8 shrink-0 items-center justify-center in-data-[shape=rounded]:rounded-lg in-data-[shape=square]:rounded-md rounded-full text-muted-foreground group-hover/input:text-foreground group-focus-visible/input:text-primary group-active/input:text-primary in-data-popup-open:text-primary in-data-invalid:text-destructive! in-data-[size=lg]:[&_svg:not([class*='size-'])]:size-5 in-data-[size=sm]:[&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='size-'])]:size-4.5";

const selectTriggerClassName =
  "cursor-pointer select-none justify-between pe-1 text-start outline-none focus-within:shadow-[inset_0_0_0_0.0625rem_var(--color-border)] data-[variant=outline]:focus-within:shadow-[inset_0_0_0_0.0625rem_var(--color-input)] data-[variant=outlined]:focus-within:shadow-[inset_0_0_0_0.0625rem_var(--color-input)] focus-visible:shadow-[inset_0_0_0_0.125rem_var(--color-primary)]! data-disabled:pointer-events-none data-disabled:opacity-38 data-invalid:shadow-[inset_0_0_0_0.125rem_var(--color-destructive)]! data-popup-open:shadow-[inset_0_0_0_0.125rem_var(--color-primary)]! [&>svg]:text-muted-foreground focus-visible:[&>svg]:text-primary data-popup-open:[&>svg]:text-primary aria-invalid:[&>svg]:text-destructive! data-invalid:[&>svg]:text-destructive!";

const selectStartAddonClassName =
  "pointer-events-none flex shrink-0 items-center justify-center in-data-invalid:text-destructive! text-muted-foreground group-focus-visible/input:text-primary in-data-popup-open:text-primary [&_svg:not([class*='size-'])]:size-4.5 in-data-[size=lg]:[&_svg:not([class*='size-'])]:size-5 in-data-[size=sm]:[&_svg:not([class*='size-'])]:size-4";

export const Select: typeof SelectPrimitive.Root = SelectPrimitive.Root;

export const SelectPortal: typeof SelectPrimitive.Portal =
  SelectPrimitive.Portal;

export interface SelectButtonProps
  extends useRender.ComponentProps<"button">,
    VariantProps<typeof inputVariants> {
  startAddon?: React.ReactNode;
}

export function SelectButton({
  className,
  variant = "filled",
  shape = "pill",
  size = "default",
  startAddon,
  render,
  children,
  ...props
}: SelectButtonProps): React.ReactElement {
  const typeValue: React.ButtonHTMLAttributes<HTMLButtonElement>["type"] =
    render ? undefined : "button";

  const defaultProps = {
    children: (
      <>
        {startAddon && (
          <span
            aria-hidden="true"
            className={selectStartAddonClassName}
            data-slot="select-start-addon"
          >
            {startAddon}
          </span>
        )}
        <span className="flex-1 truncate in-data-placeholder:text-muted-foreground/72">
          {children}
        </span>
        <span className={selectIconClassName} data-slot="select-icon">
          <ChevronsUpDownIcon aria-hidden="true" />
        </span>
      </>
    ),
    className: cn(
      inputVariants({ shape, size, variant }),
      selectTriggerClassName,
      className,
    ),
    "data-shape": shape,
    "data-size": size,
    "data-slot": "select-button",
    "data-variant": variant,
    type: typeValue,
  };

  return useRender({
    defaultTagName: "button",
    props: mergeProps<"button">(defaultProps, props),
    render,
  });
}

export type SelectTriggerProps = SelectPrimitive.Trigger.Props &
  VariantProps<typeof inputVariants> & {
    startAddon?: React.ReactNode;
  };

export function SelectTrigger({
  className,
  variant = "filled",
  shape = "pill",
  size = "default",
  startAddon,
  children,
  ...props
}: SelectTriggerProps): React.ReactElement {
  return (
    <SelectPrimitive.Trigger
      className={cn(
        inputVariants({ shape, size, variant }),
        selectTriggerClassName,
        className,
      )}
      data-shape={shape}
      data-size={size}
      data-slot="select-trigger"
      data-variant={variant}
      {...props}
    >
      {startAddon && (
        <span
          aria-hidden="true"
          className={selectStartAddonClassName}
          data-slot="select-start-addon"
        >
          {startAddon}
        </span>
      )}
      {children}
      <SelectPrimitive.Icon
        className={selectIconClassName}
        data-slot="select-icon"
      >
        <ChevronsUpDownIcon aria-hidden="true" />
      </SelectPrimitive.Icon>
    </SelectPrimitive.Trigger>
  );
}

export function SelectValue({
  className,
  ...props
}: SelectPrimitive.Value.Props): React.ReactElement {
  return (
    <SelectPrimitive.Value
      className={cn(
        "flex min-w-0 flex-1 items-center gap-2 truncate data-placeholder:text-muted-foreground/72 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
        className,
      )}
      data-slot="select-value"
      {...props}
    />
  );
}

export type SelectPopupProps = SelectPrimitive.Popup.Props &
  VariantProps<typeof menuPopupVariants> & {
    portalProps?: SelectPrimitive.Portal.Props;
    side?: SelectPrimitive.Positioner.Props["side"];
    sideOffset?: SelectPrimitive.Positioner.Props["sideOffset"];
    align?: SelectPrimitive.Positioner.Props["align"];
    alignOffset?: SelectPrimitive.Positioner.Props["alignOffset"];
    alignItemWithTrigger?: SelectPrimitive.Positioner.Props["alignItemWithTrigger"];
    anchor?: SelectPrimitive.Positioner.Props["anchor"];
  };

export function SelectPopup({
  className,
  children,
  side = "bottom",
  sideOffset = 6,
  align = "start",
  alignOffset = 0,
  alignItemWithTrigger = false,
  anchor,
  portalProps,
  colorScheme,
  ...props
}: SelectPopupProps): React.ReactElement {
  return (
    <SelectPrimitive.Portal {...portalProps}>
      <SelectPrimitive.Positioner
        align={align}
        alignItemWithTrigger={alignItemWithTrigger}
        alignOffset={alignOffset}
        anchor={anchor}
        className="z-50 select-none"
        data-slot="select-positioner"
        side={side}
        sideOffset={sideOffset}
      >
        <SelectPrimitive.Popup
          className={cn(
            menuPopupVariants({ colorScheme }),
            "group/select-popup relative flex max-h-(--available-height) w-(--anchor-width) min-w-(--anchor-width) max-w-(--available-width) flex-col overflow-hidden bg-(--menu-bg) p-1.5 shadow-[0_0_0_0.0625rem_var(--menu-ring),0_0.25rem_0.5rem_0.1875rem_rgb(0_0_0/0.15),0_0.0625rem_0.1875rem_0_rgb(0_0_0/0.3)] data-[side=none]:min-w-[calc(var(--anchor-width)+0.25rem)] data-[side=none]:origin-(--transform-origin) data-[side=none]:transform-gpu data-ending-style:transition-none! data-[side=none]:data-starting-style:[scale:1_0.75] data-[side=none]:[transition-timing-function:linear(0,0.42_7%,0.85_16%,1.03_28%,1.015_44%,1.002_65%,1),ease]",
            className,
          )}
          data-slot="select-popup"
          {...props}
        >
          <SelectPrimitive.List
            className="flex max-h-[min(var(--available-height),22rem)] flex-col gap-0.5 overflow-y-auto overflow-x-hidden overscroll-contain rounded-[inherit] [scrollbar-color:color-mix(in_oklab,var(--menu-bg),var(--menu-fg)_28%)_transparent] [scrollbar-width:thin]"
            data-slot="select-list"
          >
            {children}
          </SelectPrimitive.List>
        </SelectPrimitive.Popup>
      </SelectPrimitive.Positioner>
    </SelectPrimitive.Portal>
  );
}

export function SelectItem({
  className,
  children,
  ...props
}: SelectPrimitive.Item.Props): React.ReactElement {
  return (
    <SelectPrimitive.Item
      className={cn(
        "group relative flex min-h-9 pointer-coarse:min-h-10 cursor-default select-none items-center gap-2.5 rounded-lg px-3 py-1.5 font-medium text-sm outline-none transition-[border-radius] duration-350 ease-(--spatial)",
        "before:pointer-events-none before:absolute before:inset-0 before:rounded-[inherit] before:bg-current before:opacity-0",
        "data-highlighted:before:opacity-8 data-highlighted:active:before:opacity-10 data-highlighted:focus-visible:before:opacity-10",
        "data-selected:text-(color:--menu-sel-fg) data-selected:bg-(--menu-sel-bg)",
        "data-highlighted:rounded-xl data-selected:rounded-xl",
        "focus-visible:outline-2 focus-visible:outline-ring focus-visible:-outline-offset-2 motion-reduce:transition-none",
        "data-disabled:pointer-events-none data-disabled:opacity-38",
        "[&>svg:not([class*='size-'])]:size-4 [&>svg]:pointer-events-none [&>svg]:shrink-0",
        className,
      )}
      data-slot="select-item"
      {...props}
    >
      <SelectPrimitive.ItemText className="flex min-w-0 flex-1 items-center gap-2 truncate [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0">
        {children}
      </SelectPrimitive.ItemText>
      <SelectPrimitive.ItemIndicator className="ms-auto flex shrink-0 items-center justify-center">
        <CheckIcon aria-hidden="true" className="size-4" />
      </SelectPrimitive.ItemIndicator>
    </SelectPrimitive.Item>
  );
}

export function SelectSeparator({
  className,
  ...props
}: SelectPrimitive.Separator.Props): React.ReactElement {
  return (
    <SelectPrimitive.Separator
      className={cn("mx-2.5 my-1 h-px bg-current opacity-12", className)}
      data-slot="select-separator"
      {...props}
    />
  );
}

export function SelectGroup({
  className,
  ...props
}: SelectPrimitive.Group.Props): React.ReactElement {
  return (
    <SelectPrimitive.Group
      className={cn("flex flex-col gap-0.5 [[role=group]+&]:mt-1.5", className)}
      data-slot="select-group"
      {...props}
    />
  );
}

export function SelectLabel({
  className,
  ...props
}: SelectPrimitive.Label.Props): React.ReactElement {
  return (
    <SelectPrimitive.Label
      className={cn(
        "not-in-data-[slot=field]:mb-1.5 inline-flex cursor-default items-center gap-2 font-medium text-foreground text-sm leading-5 has-[+[data-shape=pill]]:px-1",
        className,
      )}
      data-slot="select-label"
      {...props}
    />
  );
}

export function SelectGroupLabel({
  className,
  ...props
}: SelectPrimitive.GroupLabel.Props): React.ReactElement {
  return (
    <SelectPrimitive.GroupLabel
      className={cn(
        "px-3 py-1.5 font-medium text-muted-foreground text-xs",
        className,
      )}
      data-slot="select-group-label"
      {...props}
    />
  );
}

export { SelectPrimitive, SelectPopup as SelectContent };
```

- Update the import paths to match your project setup.

## Usage [#usage]

```tsx
import {
  Select,
  SelectItem,
  SelectPopup,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select"
```

```tsx
<Select items={items}>
  <SelectTrigger>
    <SelectValue placeholder="Select an option" />
  </SelectTrigger>
  <SelectPopup>
    <SelectItem value="a">Option A</SelectItem>
    <SelectItem value="b">Option B</SelectItem>
  </SelectPopup>
</Select>
```

## Examples [#examples]

### Outline [#outline]

```tsx
import {
  Select,
  SelectItem,
  SelectLabel,
  SelectPopup,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select";

const roles = [
  { label: "Owner", value: "owner" },
  { label: "Admin", value: "admin" },
  { label: "Editor", value: "editor" },
  { label: "Viewer", value: "viewer" },
];

export default function Particle() {
  return (
    <div className="flex w-full max-w-60 flex-col">
      <Select defaultValue="editor" items={roles}>
        <SelectLabel>Role</SelectLabel>
        <SelectTrigger variant="outline">
          <SelectValue placeholder="Select a role" />
        </SelectTrigger>
        <SelectPopup>
          {roles.map((role) => (
            <SelectItem key={role.value} value={role.value}>
              {role.label}
            </SelectItem>
          ))}
        </SelectPopup>
      </Select>
    </div>
  );
}
```

### Grouped Items [#grouped-items]

```tsx
import { GlobeIcon } from "lucide-react";
import {
  Select,
  SelectGroup,
  SelectGroupLabel,
  SelectItem,
  SelectPopup,
  SelectSeparator,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select";

const timezones = [
  { label: "Pacific Time (PT)", value: "america-los_angeles" },
  { label: "Eastern Time (ET)", value: "america-new_york" },
  { label: "Brasilia Time (BRT)", value: "america-sao_paulo" },
  { label: "Greenwich Mean Time (GMT)", value: "europe-london" },
  { label: "Central European Time (CET)", value: "europe-paris" },
  { label: "Japan Standard Time (JST)", value: "asia-tokyo" },
];

export default function Particle() {
  return (
    <Select defaultValue="america-sao_paulo" items={timezones}>
      <SelectTrigger
        aria-label="Timezone"
        className="w-full max-w-64"
        startAddon={<GlobeIcon />}
      >
        <SelectValue placeholder="Select a timezone" />
      </SelectTrigger>
      <SelectPopup>
        <SelectGroup>
          <SelectGroupLabel>Americas</SelectGroupLabel>
          <SelectItem value="america-los_angeles">Pacific Time (PT)</SelectItem>
          <SelectItem value="america-new_york">Eastern Time (ET)</SelectItem>
          <SelectItem value="america-sao_paulo">Brasilia Time (BRT)</SelectItem>
        </SelectGroup>
        <SelectSeparator />
        <SelectGroup>
          <SelectGroupLabel>Europe &amp; Asia</SelectGroupLabel>
          <SelectItem value="europe-london">
            Greenwich Mean Time (GMT)
          </SelectItem>
          <SelectItem value="europe-paris">
            Central European Time (CET)
          </SelectItem>
          <SelectItem value="asia-tokyo">Japan Standard Time (JST)</SelectItem>
        </SelectGroup>
      </SelectPopup>
    </Select>
  );
}
```

### Vibrant Popup [#vibrant-popup]

```tsx
"use client";

import { MonitorIcon, MoonIcon, SunIcon } from "lucide-react";
import {
  Select,
  SelectItem,
  SelectPopup,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select";

const themes = [
  { icon: MonitorIcon, label: "System", value: "system" },
  { icon: SunIcon, label: "Light", value: "light" },
  { icon: MoonIcon, label: "Dark", value: "dark" },
] as const;

export default function Particle() {
  return (
    <Select defaultValue="system" items={themes}>
      <SelectTrigger aria-label="Theme" className="w-full max-w-52">
        <SelectValue>
          {(value: string | null) => {
            const selected = themes.find((t) => t.value === value);
            if (!selected) return "Select theme";
            const Icon = selected.icon;
            return (
              <>
                <Icon />
                <span>{selected.label}</span>
              </>
            );
          }}
        </SelectValue>
      </SelectTrigger>
      <SelectPopup colorScheme="vibrant">
        {themes.map((theme) => {
          const Icon = theme.icon;
          return (
            <SelectItem key={theme.value} value={theme.value}>
              <Icon />
              <span>{theme.label}</span>
            </SelectItem>
          );
        })}
      </SelectPopup>
    </Select>
  );
}
```

### Align Item With Trigger [#align-item-with-trigger]

```tsx
import {
  Select,
  SelectItem,
  SelectPopup,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select";

const fonts = [
  { label: "Sans-serif", value: "sans" },
  { label: "Serif", value: "serif" },
  { label: "Monospace", value: "mono" },
  { label: "System UI", value: "system" },
];

export default function Particle() {
  return (
    <Select defaultValue="sans" items={fonts}>
      <SelectTrigger aria-label="Font family" className="w-full max-w-56">
        <SelectValue placeholder="Choose a font" />
      </SelectTrigger>
      <SelectPopup alignItemWithTrigger>
        {fonts.map((font) => (
          <SelectItem key={font.value} value={font.value}>
            {font.label}
          </SelectItem>
        ))}
      </SelectPopup>
    </Select>
  );
}
```

### With Field [#with-field]

```tsx
import {
  Field,
  FieldDescription,
  FieldLabel,
} from "@/components/ui/field";
import {
  Select,
  SelectItem,
  SelectPopup,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select";

const regions = [
  { label: "US East (Virginia)", value: "us-east-1" },
  { label: "South America (São Paulo)", value: "sa-east-1" },
  { label: "Europe (Frankfurt)", value: "eu-central-1" },
  { label: "Asia Pacific (Tokyo)", value: "ap-northeast-1" },
];

export default function Particle() {
  return (
    <Field className="w-full max-w-64">
      <FieldLabel>Deployment region</FieldLabel>
      <Select defaultValue="sa-east-1" items={regions}>
        <SelectTrigger>
          <SelectValue placeholder="Select a region" />
        </SelectTrigger>
        <SelectPopup>
          {regions.map((region) => (
            <SelectItem key={region.value} value={region.value}>
              {region.label}
            </SelectItem>
          ))}
        </SelectPopup>
      </Select>
      <FieldDescription>
        Choose the region closest to your users.
      </FieldDescription>
    </Field>
  );
}
```

## API Reference [#api-reference]

### Select [#select]

Alias for Base UI `Select.Root`.

| Prop            | Type                                                        | Default | Description                                        |
| --------------- | ----------------------------------------------------------- | ------- | -------------------------------------------------- |
| `value`         | `Value`                                                     | -       | Controlled selected value                          |
| `defaultValue`  | `Value`                                                     | -       | Initial uncontrolled value                         |
| `onValueChange` | `(value: Value, eventDetails) => void`                      | -       | Callback fired when the selected value changes     |
| `items`         | `Record<string, ReactNode> \| Array<{ label, value }>`      | -       | Maps values to display labels inside `SelectValue` |
| `multiple`      | `boolean`                                                   | `false` | Allows selecting multiple items                    |
| `disabled`      | `boolean`                                                   | `false` | Disables the select control                        |
| `required`      | `boolean`                                                   | `false` | Requires a selection for form submission           |

### SelectTrigger [#selecttrigger]

Styled trigger button inheriting `Input` variants.

| Prop         | Type                                         | Default     | Description                                    |
| ------------ | -------------------------------------------- | ----------- | ---------------------------------------------- |
| `variant`    | `"filled" \| "outline" \| "outlined"`        | `"filled"`  | Tonal filled surface or crisp outlined surface |
| `shape`      | `"pill" \| "round" \| "rounded" \| "square"` | `"pill"`    | Corner radius preset                           |
| `size`       | `"sm" \| "default" \| "md" \| "lg"`          | `"default"` | Trigger height, padding, and icon size         |
| `startAddon` | `React.ReactNode`                            | -           | Leading element (such as an icon)              |

### SelectPopup [#selectpopup]

Portal, positioner, popup surface, and scrollable list (`SelectContent` is also exported as an alias).

| Prop                   | Type                                          | Default      | Description                                              |
| ---------------------- | --------------------------------------------- | ------------ | -------------------------------------------------------- |
| `colorScheme`          | `"standard" \| "vibrant"`                     | `"standard"` | Tonal popup palette inherited from `menuPopupVariants`   |
| `side`                 | `"top" \| "bottom" \| "left" \| "right"`      | `"bottom"`   | Preferred side relative to the trigger                   |
| `sideOffset`           | `number`                                      | `6`          | Gap in pixels between trigger and popup                  |
| `align`                | `"start" \| "center" \| "end"`                | `"start"`    | Alignment along the trigger axis                         |
| `alignItemWithTrigger` | `boolean`                                     | `false`      | Overlays the popup so the active item aligns over trigger |

### Subcomponents [#subcomponents]

`SelectValue`, `SelectButton`, `SelectItem`, `SelectGroup`, `SelectGroupLabel`, `SelectLabel`, `SelectSeparator`, and `SelectPortal`.
