# Select

Pick one value from a list that opens from a field.

Pick one value from a list. A field-style trigger opens a raised popup that scales out of the trigger; a single highlight glides between options under the pointer and the arrow keys alike; opening from the keyboard and the caret stay instant. Behaviour, focus and ARIA come from the Zag select machine, through Ark UI in React, Vue and Svelte.

Kind: component · Category: Inputs · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `select` machine, through Ark UI

## Add

```bash
npx fndn add select
```

It writes the folder `select/` into the project's ui folder (`index.ts`, `select.tsx`, `Select.vue`, `Select.svelte`, `select.recipe.ts`). First time: [Installation](/installation.md).

## Usage

```tsx
import { Select } from "@/components/ui/select";
```

```vue
import { Select } from "@/components/ui/select";
```

```svelte
import { Select } from "$lib/components/ui/select";
```

## Parts

In the DOM the root carries `data-slot="select"` and each part `data-slot="select-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `select` |  |  |
| `label` | `label` | `select-label` | optional |  |
| `control` | `div` | `select-control` |  |  |
| `trigger` | `button` | `select-trigger` |  | role=combobox; data-state=open\|closed; data-placeholder-shown while empty |
| `value` | `span` | `select-value` |  | Selected label, or the placeholder |
| `indicator` | `span` | `select-indicator` |  | Caret; flips while open. Carries kbd-instant: instant when the popup opens from the keyboard |
| `positioner` | `div` | `select-positioner` |  | Placed by the engine; rendered in a portal so cards cannot clip it. Exposes --transform-origin, --reference-width, --available-height |
| `content` | `div` | `select-content` |  | role=listbox popup; the shared popup surface (`lib/popup.ts`: surface, motion, keyboard-instant; stacking from base.css). data-state=open\|closed; sizes xs and sm: 26px rows (--option-height). Width: never narrower than the trigger (or 120px), then as wide as its longest option, up to 360px |
| `highlight` | `span` | `select-highlight` |  | Shared gliding highlight layer (`glideLayer` of `lib/glide.ts`); glides under the pointer and the keyboard |
| `group` | `div` | `select-group` | optional, repeats |  |
| `group-label` | `div` | `select-group-label` | optional | the shared option row's group label (`lib/option.ts`) |
| `item` | `div` | `select-item` | repeats | role=option; data-highlighted, data-state=checked\|unchecked, data-disabled; composes the shared option row (`lib/option.ts`: 30px, text.dense (12.5px), gap 8) |
| `item-text` | `span` | `select-item-text` |  | The shared option row's text (`lib/option.ts`). Never cut with an ellipsis: an option longer than the popup's 360px cap wraps |
| `item-meta` | `span` | `select-item-meta` | optional | Trailing muted note (e.g. a model tier); the shared option row's meta (`lib/option.ts`) |
| `item-indicator` | `span` | `select-item-indicator` |  | Check on the selected option, shown through the item's data-state; keeps its space on other rows so trailing notes stay aligned; the shared option row's indicator (`lib/option.ts`) |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `{ value: string; label: string; meta?: string; disabled?: boolean }[]` |  | Options in order. Strings are accepted as value=label. |
| `value` | `string` |  | Bindable (React: `defaultValue` and `onValueChange`; Vue: `v-model:value`; Svelte: `bind:value`). Selected value, or null. |
| `placeholder` | `string` | `"Select"` |  |
| `label` | `string` |  | Visible label; otherwise pass aria-label. |
| `size` | `"xs" \| "sm" \| "md" \| "lg"` | `"md"` | The shared control's sizes (`lib/control.ts`), dimensions only: xs 24px, sm 28px, md 32px, lg 36px. Up to 28px the list's rows are 26px. |
| `variant` | `"outline" \| "subtle" \| "ghost"` | `"outline"` | The shared control's looks (`lib/control.ts`), at every size. outline: the form field (field colour, hairline). subtle: the inspector (inset grey, no edge). ghost: reads as text until touched (the model picker); open, it keeps the darker fill an open ghost button keeps, with no ring or field fill. With no width it is as wide as its value, the caret right after it; given a width (a property row in a side panel) it fills it and the caret sits at the end, as the ghost combobox's does. |
| `disabled` | `boolean` | `false` |  |
| `invalid` | `boolean` | `false` |  |
| `name` | `string` |  | Form field name; renders a hidden native select. |
| `placement` | `string` | `"bottom-start"` | Preferred side; flips when there is no room. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `valueChange` | (value: string \| null) |
| `openChange` | (open: boolean) |
| `ui:set-value` | No adapter handles it (control `value` instead). { value: string \| null } |
| `ui:set-open` | No adapter handles it. { open: boolean } |

## States

`hover`, `press`, `focus-visible`, `open`, `highlighted`, `selected`, `disabled`, `invalid`

## Keyboard and accessibility

Role: combobox + listbox.

Keyboard:

- Enter / Space / ArrowDown / ArrowUp on the trigger open the list
- ArrowDown / ArrowUp move the highlight; Home / End jump
- Typing jumps to the matching option (type-ahead), open or closed
- Enter / Space select and close; Escape closes; focus returns to the trigger
- Tab closes and moves on

Notes:

- Give it a visible label or an aria-label.
- Opening and closing from the keyboard are instant; the pointer gets the scale-in. The highlight glides for the pointer and the arrow keys alike.
- Every option is readable in full: the list grows to its longest option and wraps anything longer than its cap. The trigger shows one line and may shorten the selected label; the list shows it whole.

## Motion

- popup: the shared popup surface (`lib/popup.ts`): opacity + scale from motion.popup-scale out of the trigger (--transform-origin), along the block axis only (the list is as wide as the trigger, and its sides stay on the trigger's sides however wide it is), duration.popup, easing.out-strong; closes at duration.fast; instant when opened or closed from the keyboard
- caret: rotate 180deg over duration.move, easing.out-strong; instant from the keyboard
- highlight: one layer glides between options over duration.move, easing.out-strong, under the pointer and the arrow keys alike
- rows: a pressed option darkens to color.hover-2 over duration.fast
- trigger: colour and ring over duration.fast / duration.base; the shared control's motion (`lib/control.ts`): press darkens, in every look; a trigger never scales

## Tokens

`color.field`, `color.inset`, `color.surface`, `color.hover`, `color.hover-2`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.accent`, `color.accent-tint`, `color.red`, `color.red-tint`, `shadow.hairline`, `shadow.raised`, `radius.control`, `radius.chip`, `radius.card`, `text.2xs`, `text.xs`, `text.sm`, `duration.fast`, `duration.base`, `duration.popup`, `duration.move`, `easing.out-strong`, `motion.popup-scale`, `color.line`, `text.md`

## Examples

### Deploy environment

React · `environment.tsx`

```tsx
import type { ComponentProps } from "react";
import { Select } from "@/components/ui/select";

type Props = ComponentProps<typeof Select>;

const environments: Props["items"] = [
  { value: "production", label: "Production", meta: "main" },
  { value: "staging", label: "Staging", meta: "release/2026.11" },
  { value: "preview", label: "Preview", meta: "feat/usage-alerts" },
];

export default function Environment() {
  return (
    <Select
      items={environments}
      defaultValue="staging"
      placeholder="Choose an environment"
      label="Deploy to"
      style={{ width: 240 }}
    />
  );
}
```

Vue · `environment.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Select } from "@/components/ui/select";

const environments = [
  { value: "production", label: "Production", meta: "main" },
  { value: "staging", label: "Staging", meta: "release/2026.11" },
  { value: "preview", label: "Preview", meta: "feat/usage-alerts" },
];

const environment = ref<string | null>("staging");
</script>

<template>
  <Select
    :items="environments"
    v-model:value="environment"
    placeholder="Choose an environment"
    label="Deploy to"
    style="width: 240px"
  />
</template>
```

Svelte · `environment.svelte`

```svelte
<script lang="ts">
  import { Select } from "$lib/components/ui/select";

  const environments = [
    { value: "production", label: "Production", meta: "main" },
    { value: "staging", label: "Staging", meta: "release/2026.11" },
    { value: "preview", label: "Preview", meta: "feat/usage-alerts" },
  ];

  let environment = $state<string | null>("staging");
</script>

<Select
  items={environments}
  bind:value={environment}
  placeholder="Choose an environment"
  label="Deploy to"
  style="width: 240px"
/>
```

### Filters in a toolbar

React · `deploy-filters.tsx`

```tsx
import { Button } from "@/components/ui/button";
import { Select } from "@/components/ui/select";
import { DownloadSimple } from "@phosphor-icons/react";

const statuses = ["All statuses", "Ready", "Building", "Failed", "Canceled"];
const ranges = ["Last 24 hours", "Last 7 days", "Last 30 days"];

/* sm Selects and an sm Button line up at 28px */
export default function DeployFilters() {
  return (
    <div className="flex flex-wrap items-center gap-2">
      <Select items={statuses} defaultValue="All statuses" size="sm" aria-label="Status" style={{ width: 136 }} />
      <Select items={ranges} defaultValue="Last 7 days" size="sm" aria-label="Date range" style={{ width: 136 }} />
      <Button size="sm" icon={<DownloadSimple data-slot="icon" weight="bold" />}>Export</Button>
    </div>
  );
}
```

Vue · `deploy-filters.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { PhDownloadSimple } from "@phosphor-icons/vue";
import { Button } from "@/components/ui/button";
import { Select } from "@/components/ui/select";

const statuses = ["All statuses", "Ready", "Building", "Failed", "Canceled"];
const ranges = ["Last 24 hours", "Last 7 days", "Last 30 days"];

const status = ref<string | null>("All statuses");
const range = ref<string | null>("Last 7 days");
</script>

<!-- sm Selects and an sm Button line up at 28px -->
<template>
  <div class="flex flex-wrap items-center gap-2">
    <Select :items="statuses" v-model:value="status" size="sm" aria-label="Status" style="width: 136px" />
    <Select :items="ranges" v-model:value="range" size="sm" aria-label="Date range" style="width: 136px" />
    <Button size="sm">
      <template #icon><PhDownloadSimple data-slot="icon" weight="bold" /></template>
      Export
    </Button>
  </div>
</template>
```

Svelte · `deploy-filters.svelte`

```svelte
<script lang="ts">
  import DownloadSimple from "phosphor-svelte/lib/DownloadSimpleIcon";
  import { Button } from "$lib/components/ui/button";
  import { Select } from "$lib/components/ui/select";

  const statuses = ["All statuses", "Ready", "Building", "Failed", "Canceled"];
  const ranges = ["Last 24 hours", "Last 7 days", "Last 30 days"];

  let status = $state<string | null>("All statuses");
  let range = $state<string | null>("Last 7 days");
</script>

<!-- sm Selects and an sm Button line up at 28px -->
<div class="flex flex-wrap items-center gap-2">
  <Select items={statuses} bind:value={status} size="sm" aria-label="Status" style="width: 136px" />
  <Select items={ranges} bind:value={range} size="sm" aria-label="Date range" style="width: 136px" />
  <Button size="sm">
    {#snippet icon()}<DownloadSimple data-slot="icon" weight="bold" />{/snippet}
    Export
  </Button>
</div>
```

### Member roles in a list

React · `member-roles.tsx`

```tsx
import type { ComponentProps } from "react";
import { Avatar } from "@/components/ui/avatar";
import { Select } from "@/components/ui/select";

type Props = ComponentProps<typeof Select>;

const roles: Props["items"] = [
  { value: "owner", label: "Owner", disabled: true },
  { value: "admin", label: "Admin" },
  { value: "member", label: "Member" },
  { value: "viewer", label: "Viewer" },
];

const members = [
  { name: "Maya Chen", email: "maya@northwind.example", role: "owner" },
  { name: "Daniel Okafor", email: "daniel@northwind.example", role: "admin" },
  { name: "Priya Raman", email: "priya@northwind.example", role: "viewer" },
];

/* ghost: reads as text in a dense list until it is hovered or focused */
export default function MemberRoles() {
  return (
    <ul className="m-0 flex w-full max-w-[360px] list-none flex-col gap-3 p-0">
      {members.map((member) => (
        <li key={member.email} className="flex items-center gap-3">
          <Avatar name={member.name} size={20} />
          <div className="flex min-w-0 flex-1 flex-col">
            <span className="text-sm font-medium text-ink">{member.name}</span>
            <span className="truncate text-xs text-ink-2" title={member.email}>{member.email}</span>
          </div>
          <Select
            items={roles}
            defaultValue={member.role}
            size="sm"
            variant="ghost"
            placement="bottom-end"
            disabled={member.role === "owner"}
            aria-label={`Role of ${member.name}`}
          />
        </li>
      ))}
    </ul>
  );
}
```

Vue · `member-roles.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Avatar } from "@/components/ui/avatar";
import { Select } from "@/components/ui/select";

const roles = [
  { value: "owner", label: "Owner", disabled: true },
  { value: "admin", label: "Admin" },
  { value: "member", label: "Member" },
  { value: "viewer", label: "Viewer" },
];

const members = ref([
  { name: "Maya Chen", email: "maya@northwind.example", role: "owner" },
  { name: "Daniel Okafor", email: "daniel@northwind.example", role: "admin" },
  { name: "Priya Raman", email: "priya@northwind.example", role: "viewer" },
]);
</script>

<!-- ghost: reads as text in a dense list until it is hovered or focused -->
<template>
  <ul class="m-0 flex w-full max-w-[360px] list-none flex-col gap-3 p-0">
    <li v-for="member in members" :key="member.email" class="flex items-center gap-3">
      <Avatar :name="member.name" :size="20" />
      <div class="flex min-w-0 flex-1 flex-col">
        <span class="text-sm font-medium text-ink">{{ member.name }}</span>
        <span class="truncate text-xs text-ink-2" :title="member.email">{{ member.email }}</span>
      </div>
      <Select
        :items="roles"
        v-model:value="member.role"
        size="sm"
        variant="ghost"
        placement="bottom-end"
        :disabled="member.role === 'owner'"
        :aria-label="`Role of ${member.name}`"
      />
    </li>
  </ul>
</template>
```

Svelte · `member-roles.svelte`

```svelte
<script lang="ts">
  import { Avatar } from "$lib/components/ui/avatar";
  import { Select } from "$lib/components/ui/select";

  const roles = [
    { value: "owner", label: "Owner", disabled: true },
    { value: "admin", label: "Admin" },
    { value: "member", label: "Member" },
    { value: "viewer", label: "Viewer" },
  ];

  let members = $state([
    { name: "Maya Chen", email: "maya@northwind.example", role: "owner" },
    { name: "Daniel Okafor", email: "daniel@northwind.example", role: "admin" },
    { name: "Priya Raman", email: "priya@northwind.example", role: "viewer" },
  ]);
</script>

<!-- ghost: reads as text in a dense list until it is hovered or focused -->
<ul class="m-0 flex w-full max-w-[360px] list-none flex-col gap-3 p-0">
  {#each members as member (member.email)}
    <li class="flex items-center gap-3">
      <Avatar name={member.name} size={20} />
      <div class="flex min-w-0 flex-1 flex-col">
        <span class="text-sm font-medium text-ink">{member.name}</span>
        <span class="truncate text-xs text-ink-2" title={member.email}>{member.email}</span>
      </div>
      <Select
        items={roles}
        bind:value={member.role}
        size="sm"
        variant="ghost"
        placement="bottom-end"
        disabled={member.role === "owner"}
        aria-label={`Role of ${member.name}`}
      />
    </li>
  {/each}
</ul>
```

### Plan, with prices

React · `plan.tsx`

```tsx
import type { ComponentProps } from "react";
import { Select } from "@/components/ui/select";

type Props = ComponentProps<typeof Select>;

/* meta sits at the end of each option; a long name wraps instead of being cut */
const plans: Props["items"] = [
  { value: "free", label: "Free", meta: "$0" },
  { value: "team", label: "Team", meta: "$20 / seat" },
  { value: "business", label: "Business", meta: "$45 / seat" },
  { value: "enterprise", label: "Enterprise, with SSO, audit log and an annual contract", meta: "Contact sales" },
];

export default function Plan() {
  return <Select items={plans} defaultValue="team" label="Plan" style={{ width: 260 }} />;
}
```

Vue · `plan.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Select } from "@/components/ui/select";

/* meta sits at the end of each option; a long name wraps instead of being cut */
const plans = [
  { value: "free", label: "Free", meta: "$0" },
  { value: "team", label: "Team", meta: "$20 / seat" },
  { value: "business", label: "Business", meta: "$45 / seat" },
  { value: "enterprise", label: "Enterprise, with SSO, audit log and an annual contract", meta: "Contact sales" },
];

const plan = ref<string | null>("team");
</script>

<template>
  <Select :items="plans" v-model:value="plan" label="Plan" style="width: 260px" />
</template>
```

Svelte · `plan.svelte`

```svelte
<script lang="ts">
  import { Select } from "$lib/components/ui/select";

  /* meta sits at the end of each option; a long name wraps instead of being cut */
  const plans = [
    { value: "free", label: "Free", meta: "$0" },
    { value: "team", label: "Team", meta: "$20 / seat" },
    { value: "business", label: "Business", meta: "$45 / seat" },
    { value: "enterprise", label: "Enterprise, with SSO, audit log and an annual contract", meta: "Contact sales" },
  ];

  let plan = $state<string | null>("team");
</script>

<Select items={plans} bind:value={plan} label="Plan" style="width: 260px" />
```

## Recipe

`select.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";
import { popup } from "../lib/popup";
import { option } from "../lib/option";
import { glideLayer } from "../lib/glide";
import { control, controlGhostTrigger, controlSize, controlVariant } from "../lib/control";

/* select — a control-style trigger (lib/control.ts) + raised popup that scales out of the trigger.
 * Behaviour comes from the Zag select machine (data-state, data-highlighted, data-disabled…).
 * The popup lives in a portal, so nothing below depends on the root being an ancestor.
 *
 * The popup surface, the option rows and the one gliding highlight are shared (the popup and
 * option recipes, glideLayer of lib/glide.ts), composed into the parts below; only what a select adds is written here. The positioner takes its stacking from base.css. Parts are found by
 * data-slot (select, select-trigger, select-content, select-item, …); the root slot is `base`. */

const row = option();
const ctl = control({ kind: "trigger" });

export const select = tv({
  slots: {
    base: "inline-flex flex-col gap-1.5 min-w-0 max-w-full",
    label: "text-sm font-medium text-ink",
    control: "flex min-w-0",
    /* the shared control recipe (lib/control.ts), trigger kind: the ring for keyboard focus and while
     * open, a press darkens it. The caret side is 2px tighter than the text side. */
    trigger: [
      ctl.base(),
      "inline-flex items-center justify-between gap-1.5 pe-[calc(var(--control-px)-2px)] leading-none",
    ],
    /* author text keeps its own direction (a Latin value on a right-to-left page keeps its word
     * order and is cut at its own end) while the layout follows the page */
    value: [
      /* the trigger is leading-none, so the value's line box is exactly the font size: 2px of block
       * padding, taken back by the margin, keep descenders (g, y) out of the clip, as the Button's
       * label does */
      "min-w-0 -my-0.5 py-0.5 overflow-hidden text-ellipsis whitespace-nowrap [unicode-bidi:plaintext] [text-align:match-parent]",
      "[[data-slot=select-trigger][data-placeholder-shown]_&]:text-ink-3",
    ],
    /* carries kbd-instant: a popup opened from the keyboard flips its caret at once */
    indicator: [
      "kbd-instant",
      "inline-flex shrink-0 text-[12px] text-ink-3 motion-transform-move",
      "[[data-slot=select-trigger][data-state=open]_&]:rotate-180",
    ],
    positioner: "",
    /* Width: never narrower than the trigger (or 120px), then as wide as its longest option, up to
     * 360px. An option is what the user is choosing, so it is never cut: past the cap it wraps.
     * (The engine's sameWidth option stays off in every target: it pins the list to the trigger.) */
    content: [popup({ drop: true }), "w-max min-w-[max(var(--reference-width,0px),120px)] max-w-[min(360px,calc(100vw-16px))]"],
    /* the popup's 4px: the highlight sits on the rows */
    highlight: [glideLayer, "inset-x-1"],
    item: row.base(),
    itemText: row.text(),
    itemMeta: [row.meta(), "[unicode-bidi:plaintext] [text-align:match-parent]"],
    itemIndicator: row.indicator(),
    /* groups of options (in the anatomy; the adapters render a flat list today): a hairline
     * between two groups */
    group: "[[data-slot=select-group]+&]:mt-1 [[data-slot=select-group]+&]:pt-1 [[data-slot=select-group]+&]:border-t [[data-slot=select-group]+&]:border-line",
    groupLabel: row.label(),
  },
  variants: {
    /* the shared control's sizes; up to 28px the list's rows are 26px */
    size: {
      xs: { trigger: controlSize.xs, content: "[--option-height:26px]" },
      sm: { trigger: controlSize.sm, content: "[--option-height:26px]" },
      md: { trigger: controlSize.md },
      lg: { trigger: controlSize.lg },
    },
    /* the shared control's looks: outline (the form field), subtle (the inspector), ghost (reads
     * as text until touched: the model picker; as wide as its value unless given a width, then the
     * caret at the end, as the combobox's) */
    variant: {
      outline: { trigger: controlVariant.outline },
      subtle: { trigger: controlVariant.subtle },
      ghost: { trigger: [controlVariant.ghost, controlGhostTrigger] },
    },
  },
  defaultVariants: { size: "md", variant: "outline" },
});

export type SelectRecipeProps = VariantProps<typeof select>;
```
