# Combobox

A select you can type into to filter its options.

A select you can type into. The select's field-style control holds a text input; typing filters the select's list (the shared popup, option rows and one gliding highlight), the first match is highlighted, Enter or a click chooses. Options can be found by keywords as well as their label; an optional start part (an icon, an avatar, a status) sits before the text; the caret can be left out; free text can be kept as the value when the caller allows it. Opening from the keyboard or by typing is instant; the pointer gets the popup's scale-in. Behaviour, focus and ARIA come from the Zag combobox machine, through Ark UI.

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

## Add

```bash
npx fndn add combobox
```

It writes the folder `combobox/` into the project's ui folder (`index.ts`, `combobox.tsx`, `Combobox.vue`, `Combobox.svelte`, `combobox.recipe.ts`), and what it is built from: [Button](/components/button.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { Combobox } from "@/components/ui/combobox";
```

```vue
import { Combobox } from "@/components/ui/combobox";
```

```svelte
import { Combobox } from "$lib/components/ui/combobox";
```

## Parts

In the DOM the root carries `data-slot="combobox"` and each part `data-slot="combobox-<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` | `combobox` |  |  |
| `label` | `label` | `combobox-label` | optional |  |
| `control` | `div` | `combobox-control` |  | The shared control (`lib/control.ts`), field kind: its sizes (xs 24 · sm 28 · md 32 · lg 36) and looks (outline, subtle, ghost) holding the input and the caret. A text field: the accent ring shows for every kind of focus and while the list is open. data-state=open\|closed, data-focus, data-invalid, data-disabled from the engine. |
| `start` | `span` | `combobox-start` | optional | Before the text, inside the control: an icon (14px, ink-3), an avatar or a status that says what the field holds or shows what is chosen (the assignee's avatar, a globe for a country). As far from the edge as the text would be (the size's padding), or 2px when it begins with a button (the end part's rule, mirrored); the text starts 8px after it. Text in it stays on one line and is cut at 45% of the field, with a title while cut; elements never shrink. A press on it is a press in the field (focus, and the list opens as from a click in the field); a control inside it (a button, a link) keeps its own press. Not part of the field's name: a start that carries meaning says it in its own text. |
| `input` | `input` | `combobox-input` |  | role=combobox; fills the control; aria-activedescendant follows the highlight. dir=auto: the text keeps its own direction, the alignment follows the page. 16px on coarse pointers. After a start part its text begins 8px after it; with no caret it keeps the size's padding at its end. |
| `end` | `span` | `combobox-end` | optional | After the text, inside the control, before the caret: a star, a status, a count (text ink-2, icons ink-3 and 14px). The text stops 8px before it; it keeps the size's padding from the end (2px when it ends in a button), none before the caret. |
| `trigger` | `button` | `combobox-trigger` | optional | The real Button (ghost, xs, square, muted), marked data-combobox="trigger", with an aria-label. Not a tab stop (the engine sets tabindex=-1); a click toggles the list. Left out when caret is false. |
| `indicator` | `span` | `combobox-indicator` | optional | The caret inside the trigger; flips while open over duration.move, instant from the keyboard (kbd-instant), as the select's. |
| `positioner` | `div` | `combobox-positioner` |  | Placed by the engine under the control; rendered in a portal. Exposes --transform-origin, --reference-width, --available-height |
| `content` | `div` | `combobox-content` |  | role=listbox; the shared popup surface (`lib/popup.ts`). The select's width: never narrower than the control (or 120px), then as wide as its longest option, up to 360px. sizes xs and sm: 26px rows. |
| `highlight` | `span` | `combobox-highlight` |  | Shared gliding highlight layer (`glideLayer` of `lib/glide.ts`); glides under the pointer and the arrow keys alike |
| `item` | `div` | `combobox-item` | repeats | role=option; data-highlighted, data-state=checked\|unchecked, data-disabled. Only the options whose label or one of whose keywords contains the typed text (case-insensitive) are rendered. The shared option row (`lib/option.ts`). |
| `item-icon` | `span` | `combobox-item-icon` | optional | Leading icon of an option (14px, ink-3; aria-hidden): a file icon, a site's favicon. React: a node (a Phosphor icon with data-slot="icon" weight="bold", or a 14px <img>); Vue and Svelte: a component (drawn bold). An image is 14px with a 3px radius. |
| `item-text` | `span` | `combobox-item-text` |  | Shown whole: wraps past the list's 360px cap, never cut. With highlightMatch and a label that contains the typed text: the label in ink-2, its match (item-match) in ink. |
| `item-match` | `span` | `combobox-item-match` | optional | highlightMatch: the first run of the label that matches the typed text (case-insensitive), in ink inside the label's ink-2. Colour only, never weight, so the label keeps its width as the user types. Absent when nothing is typed or the option was found by a keyword. |
| `item-meta` | `span` | `combobox-item-meta` | optional | Trailing muted note |
| `item-indicator` | `span` | `combobox-item-indicator` |  | Check on the selected option; keeps its space on other rows |
| `empty` | `div` | `combobox-empty` |  | Rendered by the engine only when nothing matches: one muted row the height of an option (emptyText). |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `{ value: string; label: string; icon: icon? (React: a node; Vue / Svelte: a component); meta?: string; disabled?: boolean; keywords?: string[] }[]` |  | Options in order. Strings are accepted as value = label. keywords: other words that find the option (ISO codes, cities, abbreviations, former names); matched like the label, never shown. With none, the field is disabled. |
| `value` | `string` |  | Bindable (React: `defaultValue` and `onValueChange`; Vue: `v-model:value`; Svelte: `bind:value`). Selected value, or null. The field shows its label. |
| `placeholder` | `string` | `"Search"` |  |
| `label` | `string` |  | Visible label; otherwise pass aria-label. |
| `start` | `node (children / slot)` |  | Before the text, inside the field (React node; Vue slot `start`, or text; Svelte snippet, or text): an icon that says what the field holds (a globe for a country), or something that shows the choice (the assignee's avatar, a status dot). Decorative unless it carries its own label; a press on it lands in the field. |
| `end` | `node (children / slot)` |  | After the text, inside the field, before the caret (React node; Vue slot `end`, or text; Svelte snippet, or text): a bookmark star (a Toggle, variant ink), a status, a count. The field's padding follows it: the text stops 8px before it, and it keeps the size's padding from the edge (2px when it ends in a button, as the caret), or sits against the caret. A press on it lands in the field; a control inside it keeps its own press. |
| `emptyText` | `string` | `"No results"` | The row shown when nothing matches. |
| `allowCustomValue` | `boolean` | `false` | Free text: Enter with no option highlighted (nothing matches) keeps what was typed, trimmed, as the value; valueChange fires with that text and the list closes. The kept text is shown as an option of its own (checked, at the end of the list) until the caller adds it to items. For pickers that may create what they pick (a new label, a tag, an email address). Off: Enter with no match puts back the chosen label. Escape, Tab and a click outside never keep text either way. |
| `highlightMatch` | `boolean` | `false` | While the user types, each option's label dims to ink-2 and the part that matches the text stays in ink (Chrome's address suggestions, an editor's quick open): the match says why the option is listed. For long lists of similar names (files, URLs, people); a short list of distinct words does not need it. |
| `triggerLabel` | `string` | `"Show options"` | aria-label of the caret button. |
| `caret` | `boolean` | `true` | The caret button at the end. false leaves it out (a dense table cell, a field whose start icon already says it opens a list): the list opens by typing, a click in the field or ArrowDown, and the text keeps the size's padding at its end. |
| `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: nothing until touched. Focused, open and invalid look the same in every variant. |
| `disabled` | `boolean` | `false` |  |
| `invalid` | `boolean` | `false` |  |
| `name` | `string` |  | Form field name; the input carries it. |
| `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) when an option is chosen, or with the typed text when allowCustomValue keeps it |
| `openChange` | (open: boolean) |
| `inputValueChange` | (text: string) as the user types and when a choice writes its label |

## States

`hover`, `focus`, `open`, `highlighted`, `selected`, `disabled`, `invalid`, `empty`

## Keyboard and accessibility

Role: combobox + listbox.

Keyboard:

- Typing opens the list and filters it; the first match is highlighted
- ArrowDown / ArrowUp open the list, then move the highlight (wraps); Home / End jump to the first and last option while it is open
- Enter chooses the highlighted option, closes the list and writes its label into the field
- Enter with nothing highlighted (no match): with allowCustomValue, keeps the typed text as the value and closes the list; without it, puts back the chosen label and closes the list
- Escape closes the list; a second Escape puts back the chosen label. Focus stays in the field
- Tab closes the list and moves on; a click outside the open list puts back the chosen label

Notes:

- Give it a visible label or an aria-label; the caret button has its own aria-label and is not a tab stop.
- Focus never leaves the field: options are reached through aria-activedescendant.
- The list opens instantly when opened from the keyboard or by typing; the pointer gets the popup's 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.
- Keywords find an option without being read out: the option is announced by its label, so a keyword should be something the label stands for (DE for Germany, Tokyo for Asia/Tokyo).
- The start part is not in the field's accessible name. A start that carries meaning (a status) says it in its own text (aria-label, title or visually hidden text); an icon that only decorates is aria-hidden.
- With caret false the field is still announced as a combobox with a list (aria-expanded, aria-controls); ArrowDown and typing open it.
- The field's text is one run, in ink: a native input cannot colour a range, and a display overlay (a host in ink, the path dimmer, as Chrome's address bar) is not worth its cost: it must copy the input's scroll, caret, selection, IME composition, font metrics and direction at every keystroke (and drifts by a subpixel at 125% scaling when it does not), and Chrome itself drops the emphasis as soon as the field is edited. A host can show the parts outside the field (in the start part, or in the options).
- The match marking (highlightMatch) is colour only and is not announced: the option is read by its whole label.

## Motion

- popup: the shared popup surface (`lib/popup.ts`): opacity + scale from motion.popup-scale out of the control, along the block axis only (the list is as wide as the control, and its sides stay on the control's sides however wide it is), duration.popup, easing.out-strong; closes at duration.fast; instant when opened or closed from the keyboard or by typing
- caret: rotate 180deg over duration.move, easing.out-strong; instant from the keyboard
- highlight: one layer glides between options over duration.move, under the pointer and the arrow keys alike
- rows: no entrance; the list changes on every keystroke. A pressed option darkens to color.hover-2 over duration.fast
- control: fill over duration.fast, ring over duration.base; the caret button presses as a Button (motion.press-scale over duration.press)
- start: no motion of its own; it changes with the value at once (an avatar swaps with the chosen person)
- free text kept by Enter: instant, as every keyboard choice; the list closes without its exit

## 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`, `text.md`, `duration.fast`, `duration.base`, `duration.popup`, `duration.move`, `duration.press`, `easing.out-strong`, `motion.popup-scale`, `motion.press-scale`

## Dependencies

- [Button](/components/button.md)

## Examples

### Assign a reviewer

React · `reviewer.tsx`

```tsx
import { Combobox } from "@/components/ui/combobox";

/* type to filter; a viewer cannot review, so that option is disabled */
const people = [
  { value: "maya", label: "Maya Chen", meta: "Owner" },
  { value: "daniel", label: "Daniel Okafor", meta: "Admin" },
  { value: "priya", label: "Priya Raman", meta: "Member" },
  { value: "lucas", label: "Lucas Moreau", meta: "Member" },
  { value: "aiko", label: "Aiko Tanaka", meta: "Member" },
  { value: "sofia", label: "Sofia Alvarez", meta: "Viewer", disabled: true },
  { value: "jonas", label: "Jonas Weber", meta: "Member" },
];

export default function Reviewer() {
  return <Combobox items={people} label="Reviewer" placeholder="Search people" emptyText="No one in Northwind matches" style={{ width: 240 }} />;
}
```

Vue · `reviewer.vue`

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

/* type to filter; a viewer cannot review, so that option is disabled */
const people = [
  { value: "maya", label: "Maya Chen", meta: "Owner" },
  { value: "daniel", label: "Daniel Okafor", meta: "Admin" },
  { value: "priya", label: "Priya Raman", meta: "Member" },
  { value: "lucas", label: "Lucas Moreau", meta: "Member" },
  { value: "aiko", label: "Aiko Tanaka", meta: "Member" },
  { value: "sofia", label: "Sofia Alvarez", meta: "Viewer", disabled: true },
  { value: "jonas", label: "Jonas Weber", meta: "Member" },
];

const reviewer = ref<string | null>(null);
</script>

<template>
  <Combobox :items="people" v-model:value="reviewer" label="Reviewer" placeholder="Search people" empty-text="No one in Northwind matches" style="width: 240px" />
</template>
```

Svelte · `reviewer.svelte`

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

  /* type to filter; a viewer cannot review, so that option is disabled */
  const people = [
    { value: "maya", label: "Maya Chen", meta: "Owner" },
    { value: "daniel", label: "Daniel Okafor", meta: "Admin" },
    { value: "priya", label: "Priya Raman", meta: "Member" },
    { value: "lucas", label: "Lucas Moreau", meta: "Member" },
    { value: "aiko", label: "Aiko Tanaka", meta: "Member" },
    { value: "sofia", label: "Sofia Alvarez", meta: "Viewer", disabled: true },
    { value: "jonas", label: "Jonas Weber", meta: "Member" },
  ];

  let reviewer = $state<string | null>(null);
</script>

<Combobox items={people} bind:value={reviewer} label="Reviewer" placeholder="Search people" emptyText="No one in Northwind matches" style="width: 240px" />
```

### Branch in a deploy bar

React · `branch-to-deploy.tsx`

```tsx
import { Button } from "@/components/ui/button";
import { Combobox } from "@/components/ui/combobox";
import { RocketLaunch } from "@phosphor-icons/react";

const branches = [
  { value: "main", label: "main", meta: "2 min ago" },
  { value: "feat/usage-alerts", label: "feat/usage-alerts", meta: "1 h ago" },
  { value: "fix/invoice-rounding", label: "fix/invoice-rounding", meta: "Yesterday" },
  { value: "release/2026.11", label: "release/2026.11", meta: "Nov 12" },
  { value: "chore/upgrade-node-22-and-pnpm-11-across-workspace", label: "chore/upgrade-node-22-and-pnpm-11-across-workspace", meta: "Nov 3" },
];

/* sm: the combobox and the sm Button share the 28px row */
export default function BranchToDeploy() {
  return (
    <div className="flex items-center gap-2">
      <Combobox items={branches} defaultValue="main" size="sm" aria-label="Branch" placeholder="Search branches" style={{ width: 200 }} />
      <Button size="sm" variant="primary" icon={<RocketLaunch data-slot="icon" weight="bold" />}>Deploy</Button>
    </div>
  );
}
```

Vue · `branch-to-deploy.vue`

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

const branches = [
  { value: "main", label: "main", meta: "2 min ago" },
  { value: "feat/usage-alerts", label: "feat/usage-alerts", meta: "1 h ago" },
  { value: "fix/invoice-rounding", label: "fix/invoice-rounding", meta: "Yesterday" },
  { value: "release/2026.11", label: "release/2026.11", meta: "Nov 12" },
  { value: "chore/upgrade-node-22-and-pnpm-11-across-workspace", label: "chore/upgrade-node-22-and-pnpm-11-across-workspace", meta: "Nov 3" },
];

const branch = ref<string | null>("main");
</script>

<!-- sm: the combobox and the sm Button share the 28px row -->
<template>
  <div class="flex items-center gap-2">
    <Combobox :items="branches" v-model:value="branch" size="sm" aria-label="Branch" placeholder="Search branches" style="width: 200px" />
    <Button size="sm" variant="primary">
      <template #icon><PhRocketLaunch data-slot="icon" weight="bold" /></template>
      Deploy
    </Button>
  </div>
</template>
```

Svelte · `branch-to-deploy.svelte`

```svelte
<script lang="ts">
  import RocketLaunch from "phosphor-svelte/lib/RocketLaunchIcon";
  import { Button } from "$lib/components/ui/button";
  import { Combobox } from "$lib/components/ui/combobox";

  const branches = [
    { value: "main", label: "main", meta: "2 min ago" },
    { value: "feat/usage-alerts", label: "feat/usage-alerts", meta: "1 h ago" },
    { value: "fix/invoice-rounding", label: "fix/invoice-rounding", meta: "Yesterday" },
    { value: "release/2026.11", label: "release/2026.11", meta: "Nov 12" },
    { value: "chore/upgrade-node-22-and-pnpm-11-across-workspace", label: "chore/upgrade-node-22-and-pnpm-11-across-workspace", meta: "Nov 3" },
  ];

  let branch = $state<string | null>("main");
</script>

<!-- sm: the combobox and the sm Button share the 28px row -->
<div class="flex items-center gap-2">
  <Combobox items={branches} bind:value={branch} size="sm" aria-label="Branch" placeholder="Search branches" style="width: 200px" />
  <Button size="sm" variant="primary">
    {#snippet icon()}<RocketLaunch data-slot="icon" weight="bold" />{/snippet}
    Deploy
  </Button>
</div>
```

### A browser's address bar, with a bookmark star

React · `address-bar.tsx`

```tsx
import { useState } from "react";
import { Lock, Star } from "@phosphor-icons/react";
import { Button } from "@/components/ui/button";
import { Combobox } from "@/components/ui/combobox";
import { Toggle } from "@/components/ui/toggle";

const pages = [
  { value: "https://status.northwind.example", label: "status.northwind.example", meta: "Status · Northwind" },
  { value: "https://app.northwind.example/web-app/deploys", label: "app.northwind.example/web-app/deploys", meta: "Deploys · web-app" },
  { value: "https://app.northwind.example/billing-api/pull/482", label: "app.northwind.example/billing-api/pull/482", meta: "#482 Add retry to webhook delivery" },
];

/* a browser's address bar: the site-information button in `start` (a button: it sits 2px from the
 * edge, as the star does at the end), the bookmark star in `end` (a muted ghost Toggle:
 * the filled star and the pressed fill when bookmarked); no caret, the suggestions open as you type */
export default function AddressBar() {
  const [bookmarked, setBookmarked] = useState(false);
  return (
    <Combobox
      items={pages}
      defaultValue="https://app.northwind.example/web-app/deploys"
      aria-label="Address and search"
      placeholder="Search or enter address"
      variant="subtle"
      caret={false}
      start={<Button variant="ghost" size="xs" square muted aria-label="View site information" icon={<Lock data-slot="icon" weight="bold" />} />}
      end={
        <Toggle
          variant="ghost"
          size="xs"
          square
          muted
          tooltip={bookmarked ? "Edit bookmark" : "Bookmark this tab"}
          pressed={bookmarked}
          onPressedChange={setBookmarked}
          icon={<Star data-slot="icon" weight={bookmarked ? "fill" : "bold"} />}
        />
      }
      style={{ width: 360 }}
    />
  );
}
```

Vue · `address-bar.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { PhLock, PhStar } from "@phosphor-icons/vue";
import { Button } from "@/components/ui/button";
import { Combobox } from "@/components/ui/combobox";
import { Toggle } from "@/components/ui/toggle";

const pages = [
  { value: "https://status.northwind.example", label: "status.northwind.example", meta: "Status · Northwind" },
  { value: "https://app.northwind.example/web-app/deploys", label: "app.northwind.example/web-app/deploys", meta: "Deploys · web-app" },
  { value: "https://app.northwind.example/billing-api/pull/482", label: "app.northwind.example/billing-api/pull/482", meta: "#482 Add retry to webhook delivery" },
];

const address = ref<string | null>("https://app.northwind.example/web-app/deploys");
const bookmarked = ref(false);
</script>

<!-- a browser's address bar: the site-information button in `start` (a button: it sits 2px from the
     edge, as the star does at the end), the bookmark star in `end` (a muted ghost Toggle:
     the filled star and the pressed fill when bookmarked); no caret, the suggestions open as you type -->
<template>
  <Combobox
    v-model:value="address"
    :items="pages"
    aria-label="Address and search"
    placeholder="Search or enter address"
    variant="subtle"
    :caret="false"
    style="width: 360px"
  >
    <template #start>
      <Button variant="ghost" size="xs" square muted aria-label="View site information">
        <template #icon><PhLock data-slot="icon" weight="bold" /></template>
      </Button>
    </template>
    <template #end>
      <Toggle
        v-model:pressed="bookmarked"
        variant="ghost"
        size="xs"
        square
        muted
        :tooltip="bookmarked ? 'Edit bookmark' : 'Bookmark this tab'"
      >
        <template #icon><PhStar data-slot="icon" :weight="bookmarked ? 'fill' : 'bold'" /></template>
      </Toggle>
    </template>
  </Combobox>
</template>
```

Svelte · `address-bar.svelte`

```svelte
<script lang="ts">
  import Lock from "phosphor-svelte/lib/LockIcon";
  import Star from "phosphor-svelte/lib/StarIcon";
  import { Button } from "$lib/components/ui/button";
  import { Combobox } from "$lib/components/ui/combobox";
  import { Toggle } from "$lib/components/ui/toggle";

  const pages = [
    { value: "https://status.northwind.example", label: "status.northwind.example", meta: "Status · Northwind" },
    { value: "https://app.northwind.example/web-app/deploys", label: "app.northwind.example/web-app/deploys", meta: "Deploys · web-app" },
    { value: "https://app.northwind.example/billing-api/pull/482", label: "app.northwind.example/billing-api/pull/482", meta: "#482 Add retry to webhook delivery" },
  ];

  let address = $state<string | null>("https://app.northwind.example/web-app/deploys");
  let bookmarked = $state(false);
</script>

<!-- a browser's address bar: the site-information button in `start` (a button: it sits 2px from the
     edge, as the star does at the end), the bookmark star in `end` (a muted ghost Toggle:
     the filled star and the pressed fill when bookmarked); no caret, the suggestions open as you type -->
<Combobox
  items={pages}
  bind:value={address}
  aria-label="Address and search"
  placeholder="Search or enter address"
  variant="subtle"
  caret={false}
  style="width: 360px"
>
  {#snippet start()}
    <Button variant="ghost" size="xs" square muted aria-label="View site information">
      {#snippet icon()}<Lock data-slot="icon" weight="bold" />{/snippet}
    </Button>
  {/snippet}
  {#snippet end()}
    <Toggle
      bind:pressed={bookmarked}
      variant="ghost"
      size="xs"
      square
      muted
      tooltip={bookmarked ? "Edit bookmark" : "Bookmark this tab"}
    >
      {#snippet icon()}<Star data-slot="icon" weight={bookmarked ? "fill" : "bold"} />{/snippet}
    </Toggle>
  {/snippet}
</Combobox>
```

### Timezone, with UTC offsets

React · `timezone.tsx`

```tsx
import { Combobox } from "@/components/ui/combobox";

/* meta carries what tells similar options apart: here the offset */
const zones = [
  { value: "America/Los_Angeles", label: "Los Angeles", meta: "UTC−08:00" },
  { value: "America/New_York", label: "New York", meta: "UTC−05:00" },
  { value: "America/Sao_Paulo", label: "São Paulo", meta: "UTC−03:00" },
  { value: "Europe/London", label: "London", meta: "UTC+00:00" },
  { value: "Europe/Berlin", label: "Berlin", meta: "UTC+01:00" },
  { value: "Asia/Kolkata", label: "Kolkata", meta: "UTC+05:30" },
  { value: "Asia/Tokyo", label: "Tokyo", meta: "UTC+09:00" },
  { value: "Australia/Sydney", label: "Sydney", meta: "UTC+11:00" },
];

export default function Timezone() {
  return <Combobox items={zones} defaultValue="Europe/Berlin" label="Timezone" placeholder="Search cities" style={{ width: 260 }} />;
}
```

Vue · `timezone.vue`

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

/* meta carries what tells similar options apart: here the offset */
const zones = [
  { value: "America/Los_Angeles", label: "Los Angeles", meta: "UTC−08:00" },
  { value: "America/New_York", label: "New York", meta: "UTC−05:00" },
  { value: "America/Sao_Paulo", label: "São Paulo", meta: "UTC−03:00" },
  { value: "Europe/London", label: "London", meta: "UTC+00:00" },
  { value: "Europe/Berlin", label: "Berlin", meta: "UTC+01:00" },
  { value: "Asia/Kolkata", label: "Kolkata", meta: "UTC+05:30" },
  { value: "Asia/Tokyo", label: "Tokyo", meta: "UTC+09:00" },
  { value: "Australia/Sydney", label: "Sydney", meta: "UTC+11:00" },
];

const zone = ref<string | null>("Europe/Berlin");
</script>

<template>
  <Combobox :items="zones" v-model:value="zone" label="Timezone" placeholder="Search cities" style="width: 260px" />
</template>
```

Svelte · `timezone.svelte`

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

  /* meta carries what tells similar options apart: here the offset */
  const zones = [
    { value: "America/Los_Angeles", label: "Los Angeles", meta: "UTC−08:00" },
    { value: "America/New_York", label: "New York", meta: "UTC−05:00" },
    { value: "America/Sao_Paulo", label: "São Paulo", meta: "UTC−03:00" },
    { value: "Europe/London", label: "London", meta: "UTC+00:00" },
    { value: "Europe/Berlin", label: "Berlin", meta: "UTC+01:00" },
    { value: "Asia/Kolkata", label: "Kolkata", meta: "UTC+05:30" },
    { value: "Asia/Tokyo", label: "Tokyo", meta: "UTC+09:00" },
    { value: "Australia/Sydney", label: "Sydney", meta: "UTC+11:00" },
  ];

  let zone = $state<string | null>("Europe/Berlin");
</script>

<Combobox items={zones} bind:value={zone} label="Timezone" placeholder="Search cities" style="width: 260px" />
```

### Billing country decides the tax

React · `billing-country.tsx`

```tsx
import { useState } from "react";
import { Combobox } from "@/components/ui/combobox";

const countries = ["Brazil", "Canada", "France", "Germany", "India", "Japan", "Netherlands", "United Kingdom", "United States"];
const vat = ["France", "Germany", "Netherlands"];

export default function BillingCountry() {
  const [country, setCountry] = useState<string | null>("Germany");
  return (
    <div className="flex flex-col gap-2" style={{ width: 260 }}>
      <Combobox items={countries} value={country} onValueChange={setCountry} label="Billing country" placeholder="Search countries" />
      <p className="m-0 text-sm text-ink-2">
        {country === null ? "Taxes are worked out from your country." : vat.includes(country) ? `VAT is added to invoices for ${country}.` : `No VAT is added for ${country}.`}
      </p>
    </div>
  );
}
```

Vue · `billing-country.vue`

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

const countries = ["Brazil", "Canada", "France", "Germany", "India", "Japan", "Netherlands", "United Kingdom", "United States"];
const vat = ["France", "Germany", "Netherlands"];

const country = ref<string | null>("Germany");
</script>

<template>
  <div class="flex flex-col gap-2" style="width: 260px">
    <Combobox :items="countries" v-model:value="country" label="Billing country" placeholder="Search countries" />
    <p class="m-0 text-sm text-ink-2">
      {{ country === null ? "Taxes are worked out from your country." : vat.includes(country) ? `VAT is added to invoices for ${country}.` : `No VAT is added for ${country}.` }}
    </p>
  </div>
</template>
```

Svelte · `billing-country.svelte`

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

  const countries = ["Brazil", "Canada", "France", "Germany", "India", "Japan", "Netherlands", "United Kingdom", "United States"];
  const vat = ["France", "Germany", "Netherlands"];

  let country = $state<string | null>("Germany");
</script>

<div class="flex flex-col gap-2" style="width: 260px">
  <Combobox items={countries} bind:value={country} label="Billing country" placeholder="Search countries" />
  <p class="m-0 text-sm text-ink-2">
    {country === null ? "Taxes are worked out from your country." : vat.includes(country) ? `VAT is added to invoices for ${country}.` : `No VAT is added for ${country}.`}
  </p>
</div>
```

### Assignee in an issue's side panel

React · `assignee-in-side-panel.tsx`

```tsx
import { useState } from "react";
import { User } from "@phosphor-icons/react";
import { Avatar } from "@/components/ui/avatar";
import { Combobox } from "@/components/ui/combobox";

const members = [
  { value: "maya", label: "Maya Chen", meta: "Owner" },
  { value: "daniel", label: "Daniel Okafor", meta: "Admin" },
  { value: "priya", label: "Priya Raman", meta: "Member" },
  { value: "lucas", label: "Lucas Moreau", meta: "Member" },
  { value: "aiko", label: "Aiko Tanaka", meta: "Member" },
  { value: "jonas", label: "Jonas Weber", meta: "Member" },
];

/* a property row of an issue: ghost and without a caret it reads as text until touched;
 * the start shows who is assigned (the name is already the field's text, so it is decorative) */
export default function AssigneeInSidePanel() {
  const [assignee, setAssignee] = useState<string | null>("priya");
  const person = members.find((member) => member.value === assignee);
  return (
    <div className="flex items-center gap-2 text-sm" style={{ width: 280 }}>
      <span className="w-20 shrink-0 text-ink-2">Assignee</span>
      <Combobox
        items={members}
        value={assignee}
        onValueChange={setAssignee}
        aria-label="Assignee"
        placeholder="Unassigned"
        emptyText="No one in Northwind matches"
        size="sm"
        variant="ghost"
        caret={false}
        start={person ? <Avatar name={person.label} size="16" aria-hidden="true" /> : <User data-slot="icon" weight="bold" />}
        className="flex-1"
      />
    </div>
  );
}
```

Vue · `assignee-in-side-panel.vue`

```vue
<script setup lang="ts">
import { computed, ref } from "vue";
import { PhUser } from "@phosphor-icons/vue";
import { Avatar } from "@/components/ui/avatar";
import { Combobox } from "@/components/ui/combobox";

const members = [
  { value: "maya", label: "Maya Chen", meta: "Owner" },
  { value: "daniel", label: "Daniel Okafor", meta: "Admin" },
  { value: "priya", label: "Priya Raman", meta: "Member" },
  { value: "lucas", label: "Lucas Moreau", meta: "Member" },
  { value: "aiko", label: "Aiko Tanaka", meta: "Member" },
  { value: "jonas", label: "Jonas Weber", meta: "Member" },
];

const assignee = ref<string | null>("priya");
const person = computed(() => members.find((member) => member.value === assignee.value));
</script>

<!-- a property row of an issue: ghost and without a caret it reads as text until touched;
     the start shows who is assigned (the name is already the field's text, so it is decorative) -->
<template>
  <div class="flex items-center gap-2 text-sm" style="width: 280px">
    <span class="w-20 shrink-0 text-ink-2">Assignee</span>
    <Combobox
      :items="members"
      v-model:value="assignee"
      aria-label="Assignee"
      placeholder="Unassigned"
      empty-text="No one in Northwind matches"
      size="sm"
      variant="ghost"
      :caret="false"
      class="flex-1"
    >
      <template #start>
        <Avatar v-if="person" :name="person.label" :size="16" aria-hidden="true" />
        <PhUser v-else data-slot="icon" weight="bold" />
      </template>
    </Combobox>
  </div>
</template>
```

Svelte · `assignee-in-side-panel.svelte`

```svelte
<script lang="ts">
  import User from "phosphor-svelte/lib/UserIcon";
  import { Avatar } from "$lib/components/ui/avatar";
  import { Combobox } from "$lib/components/ui/combobox";

  const members = [
    { value: "maya", label: "Maya Chen", meta: "Owner" },
    { value: "daniel", label: "Daniel Okafor", meta: "Admin" },
    { value: "priya", label: "Priya Raman", meta: "Member" },
    { value: "lucas", label: "Lucas Moreau", meta: "Member" },
    { value: "aiko", label: "Aiko Tanaka", meta: "Member" },
    { value: "jonas", label: "Jonas Weber", meta: "Member" },
  ];

  let assignee = $state<string | null>("priya");
  const person = $derived(members.find((member) => member.value === assignee));
</script>

<!-- a property row of an issue: ghost and without a caret it reads as text until touched;
     the start shows who is assigned (the name is already the field's text, so it is decorative) -->
<div class="flex items-center gap-2 text-sm" style="width: 280px">
  <span class="w-20 shrink-0 text-ink-2">Assignee</span>
  <Combobox
    items={members}
    bind:value={assignee}
    aria-label="Assignee"
    placeholder="Unassigned"
    emptyText="No one in Northwind matches"
    size="sm"
    variant="ghost"
    caret={false}
    class="flex-1"
  >
    {#snippet start()}
      {#if person}<Avatar name={person.label} size={16} aria-hidden="true" />{:else}<User data-slot="icon" weight="bold" />{/if}
    {/snippet}
  </Combobox>
</div>
```

### Country, found by its code or a city

React · `country-by-code.tsx`

```tsx
import { Globe } from "@phosphor-icons/react";
import { Combobox } from "@/components/ui/combobox";

/* keywords find an option without being shown: "jpn", "tokyo" or "nippon" all find Japan */
const countries = [
  { value: "DE", label: "Germany", meta: "DE", keywords: ["DEU", "Deutschland", "Berlin", "Munich", "Frankfurt"] },
  { value: "JP", label: "Japan", meta: "JP", keywords: ["JPN", "Nippon", "Tokyo", "Osaka"] },
  { value: "GB", label: "United Kingdom", meta: "GB", keywords: ["GBR", "UK", "Britain", "England", "London"] },
  { value: "US", label: "United States", meta: "US", keywords: ["USA", "America", "New York", "San Francisco"] },
  { value: "BR", label: "Brazil", meta: "BR", keywords: ["BRA", "Brasil", "São Paulo", "Sao Paulo", "Rio de Janeiro"] },
  { value: "IN", label: "India", meta: "IN", keywords: ["IND", "Bharat", "Bengaluru", "Mumbai"] },
  { value: "NL", label: "Netherlands", meta: "NL", keywords: ["NLD", "Holland", "Nederland", "Amsterdam"] },
  { value: "CH", label: "Switzerland", meta: "CH", keywords: ["CHE", "Schweiz", "Suisse", "Zurich", "Geneva"] },
];

export default function CountryByCode() {
  return (
    <Combobox
      items={countries}
      defaultValue="DE"
      label="Company country"
      placeholder="Country, code or city"
      emptyText="No country matches"
      start={<Globe data-slot="icon" weight="bold" />}
      style={{ width: 260 }}
    />
  );
}
```

Vue · `country-by-code.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { PhGlobe } from "@phosphor-icons/vue";
import { Combobox } from "@/components/ui/combobox";

/* keywords find an option without being shown: "jpn", "tokyo" or "nippon" all find Japan */
const countries = [
  { value: "DE", label: "Germany", meta: "DE", keywords: ["DEU", "Deutschland", "Berlin", "Munich", "Frankfurt"] },
  { value: "JP", label: "Japan", meta: "JP", keywords: ["JPN", "Nippon", "Tokyo", "Osaka"] },
  { value: "GB", label: "United Kingdom", meta: "GB", keywords: ["GBR", "UK", "Britain", "England", "London"] },
  { value: "US", label: "United States", meta: "US", keywords: ["USA", "America", "New York", "San Francisco"] },
  { value: "BR", label: "Brazil", meta: "BR", keywords: ["BRA", "Brasil", "São Paulo", "Sao Paulo", "Rio de Janeiro"] },
  { value: "IN", label: "India", meta: "IN", keywords: ["IND", "Bharat", "Bengaluru", "Mumbai"] },
  { value: "NL", label: "Netherlands", meta: "NL", keywords: ["NLD", "Holland", "Nederland", "Amsterdam"] },
  { value: "CH", label: "Switzerland", meta: "CH", keywords: ["CHE", "Schweiz", "Suisse", "Zurich", "Geneva"] },
];

const country = ref<string | null>("DE");
</script>

<template>
  <Combobox
    :items="countries"
    v-model:value="country"
    label="Company country"
    placeholder="Country, code or city"
    empty-text="No country matches"
    style="width: 260px"
  >
    <template #start><PhGlobe data-slot="icon" weight="bold" /></template>
  </Combobox>
</template>
```

Svelte · `country-by-code.svelte`

```svelte
<script lang="ts">
  import Globe from "phosphor-svelte/lib/GlobeIcon";
  import { Combobox } from "$lib/components/ui/combobox";

  /* keywords find an option without being shown: "jpn", "tokyo" or "nippon" all find Japan */
  const countries = [
    { value: "DE", label: "Germany", meta: "DE", keywords: ["DEU", "Deutschland", "Berlin", "Munich", "Frankfurt"] },
    { value: "JP", label: "Japan", meta: "JP", keywords: ["JPN", "Nippon", "Tokyo", "Osaka"] },
    { value: "GB", label: "United Kingdom", meta: "GB", keywords: ["GBR", "UK", "Britain", "England", "London"] },
    { value: "US", label: "United States", meta: "US", keywords: ["USA", "America", "New York", "San Francisco"] },
    { value: "BR", label: "Brazil", meta: "BR", keywords: ["BRA", "Brasil", "São Paulo", "Sao Paulo", "Rio de Janeiro"] },
    { value: "IN", label: "India", meta: "IN", keywords: ["IND", "Bharat", "Bengaluru", "Mumbai"] },
    { value: "NL", label: "Netherlands", meta: "NL", keywords: ["NLD", "Holland", "Nederland", "Amsterdam"] },
    { value: "CH", label: "Switzerland", meta: "CH", keywords: ["CHE", "Schweiz", "Suisse", "Zurich", "Geneva"] },
  ];

  let country = $state<string | null>("DE");
</script>

<Combobox
  items={countries}
  bind:value={country}
  label="Company country"
  placeholder="Country, code or city"
  emptyText="No country matches"
  style="width: 260px"
>
  {#snippet start()}<Globe data-slot="icon" weight="bold" />{/snippet}
</Combobox>
```

### Label, or create a new one

React · `new-label.tsx`

```tsx
import { useState } from "react";
import { Tag } from "@phosphor-icons/react";
import { Combobox } from "@/components/ui/combobox";

/* allowCustomValue: Enter on a name no label has keeps it; the handler adds it to the list */
export default function NewLabel() {
  const [labels, setLabels] = useState(["bug", "feature", "docs", "performance", "good first issue"]);
  const [label, setLabel] = useState<string | null>(null);
  const choose = (next: string | null) => {
    if (next && !labels.includes(next)) setLabels([...labels, next]);
    setLabel(next);
  };
  return (
    <Combobox
      items={labels}
      value={label}
      onValueChange={choose}
      allowCustomValue
      label="Label"
      placeholder="Find or create a label"
      emptyText="No such label: press Enter to create it"
      start={<Tag data-slot="icon" weight="bold" />}
      style={{ width: 260 }}
    />
  );
}
```

Vue · `new-label.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { PhTag } from "@phosphor-icons/vue";
import { Combobox } from "@/components/ui/combobox";

/* allowCustomValue: Enter on a name no label has keeps it; the handler adds it to the list */
const labels = ref(["bug", "feature", "docs", "performance", "good first issue"]);
const label = ref<string | null>(null);
function choose(next: string | null) {
  if (next && !labels.value.includes(next)) labels.value = [...labels.value, next];
  label.value = next;
}
</script>

<template>
  <Combobox
    :items="labels"
    :value="label"
    allow-custom-value
    label="Label"
    placeholder="Find or create a label"
    empty-text="No such label: press Enter to create it"
    style="width: 260px"
    @value-change="choose"
  >
    <template #start><PhTag data-slot="icon" weight="bold" /></template>
  </Combobox>
</template>
```

Svelte · `new-label.svelte`

```svelte
<script lang="ts">
  import Tag from "phosphor-svelte/lib/TagIcon";
  import { Combobox } from "$lib/components/ui/combobox";

  /* allowCustomValue: Enter on a name no label has keeps it; the handler adds it to the list */
  let labels = $state(["bug", "feature", "docs", "performance", "good first issue"]);
  let label = $state<string | null>(null);
  function choose(next: string | null) {
    if (next && !labels.includes(next)) labels = [...labels, next];
    label = next;
  }
</script>

<Combobox
  items={labels}
  value={label}
  onvaluechange={choose}
  allowCustomValue
  label="Label"
  placeholder="Find or create a label"
  emptyText="No such label: press Enter to create it"
  style="width: 260px"
>
  {#snippet start()}<Tag data-slot="icon" weight="bold" />{/snippet}
</Combobox>
```

### Go to file, the typed part marked

React · `go-to-file.tsx`

```tsx
import { File, FileText, Gear } from "@phosphor-icons/react";
import { Combobox, type ComboboxItem } from "@/components/ui/combobox";

/* an editor's "Go to file": each file leads with its icon, its folder after it; as you type, the
 * part of each name you typed stays in ink and the rest dims, so you see why a file is listed */
const files: ComboboxItem[] = [
  { value: "src/middleware/rate-limit.ts", label: "rate-limit.ts", meta: "src/middleware", icon: <File data-slot="icon" weight="bold" /> },
  { value: "src/middleware/rate-limit.test.ts", label: "rate-limit.test.ts", meta: "src/middleware", icon: <File data-slot="icon" weight="bold" /> },
  { value: "src/webhooks/retry-policy.ts", label: "retry-policy.ts", meta: "src/webhooks", icon: <File data-slot="icon" weight="bold" /> },
  { value: "docs/rate-limits.md", label: "rate-limits.md", meta: "docs", icon: <FileText data-slot="icon" weight="bold" /> },
  { value: "config/limits.yaml", label: "limits.yaml", meta: "config", icon: <Gear data-slot="icon" weight="bold" /> },
];

export default function GoToFile() {
  return <Combobox items={files} highlightMatch aria-label="Go to file" placeholder="Go to file" emptyText="No file matches" style={{ width: 320 }} />;
}
```

Vue · `go-to-file.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { PhFile, PhFileText, PhGear } from "@phosphor-icons/vue";
import { Combobox, type ComboboxItem } from "@/components/ui/combobox";

/* an editor's "Go to file": each file leads with its icon, its folder after it; as you type, the
 * part of each name you typed stays in ink and the rest dims, so you see why a file is listed */
const files: ComboboxItem[] = [
  { value: "src/middleware/rate-limit.ts", label: "rate-limit.ts", meta: "src/middleware", icon: PhFile },
  { value: "src/middleware/rate-limit.test.ts", label: "rate-limit.test.ts", meta: "src/middleware", icon: PhFile },
  { value: "src/webhooks/retry-policy.ts", label: "retry-policy.ts", meta: "src/webhooks", icon: PhFile },
  { value: "docs/rate-limits.md", label: "rate-limits.md", meta: "docs", icon: PhFileText },
  { value: "config/limits.yaml", label: "limits.yaml", meta: "config", icon: PhGear },
];

const file = ref<string | null>(null);
</script>

<template>
  <Combobox v-model:value="file" :items="files" highlight-match aria-label="Go to file" placeholder="Go to file" empty-text="No file matches" style="width: 320px" />
</template>
```

Svelte · `go-to-file.svelte`

```svelte
<script lang="ts">
  import File from "phosphor-svelte/lib/FileIcon";
  import FileText from "phosphor-svelte/lib/FileTextIcon";
  import Gear from "phosphor-svelte/lib/GearIcon";
  import { Combobox, type ComboboxItem } from "$lib/components/ui/combobox";

  /* an editor's "Go to file": each file leads with its icon, its folder after it; as you type, the
   * part of each name you typed stays in ink and the rest dims, so you see why a file is listed */
  const files: ComboboxItem[] = [
    { value: "src/middleware/rate-limit.ts", label: "rate-limit.ts", meta: "src/middleware", icon: File },
    { value: "src/middleware/rate-limit.test.ts", label: "rate-limit.test.ts", meta: "src/middleware", icon: File },
    { value: "src/webhooks/retry-policy.ts", label: "retry-policy.ts", meta: "src/webhooks", icon: File },
    { value: "docs/rate-limits.md", label: "rate-limits.md", meta: "docs", icon: FileText },
    { value: "config/limits.yaml", label: "limits.yaml", meta: "config", icon: Gear },
  ];

  let file = $state<string | null>(null);
</script>

<Combobox items={files} bind:value={file} highlightMatch aria-label="Go to file" placeholder="Go to file" emptyText="No file matches" style="width: 320px" />
```

## Recipe

`combobox.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, controlSize, controlVariant } from "../lib/control";

/* combobox — a select you can type into: the select's field-style control holding a text input,
 * and the select's list (popup surface, option rows, one gliding highlight) filtered by what is
 * typed. Behaviour comes from the Zag combobox machine (data-state, data-highlighted, data-focus…).
 * The popup lives in a portal, so nothing below depends on the root being an ancestor.
 *
 * The control is the shared control recipe (lib/control.ts), field kind: it shows the ring for every
 * kind of focus (the Input's rule), pointer included, and keeps it while the list is open (focus
 * stays in the input). Its sizes (xs 24 · sm 28 · md 32 · lg 36) and looks (outline, subtle,
 * ghost) are the control's. The caret is a real
 * Button (ghost, xs, square, muted) marked data-combobox="trigger"; its caret flips like the
 * select's, instant from the keyboard (kbd-instant on the indicator part); `caret: false` leaves it
 * out. An optional start part (an icon, an avatar, a status) sits before the text, and an optional
 * end part (a star, a status) after it, before the caret.
 *
 * Options may lead with an icon (a favicon, a file icon: the shared option row's icon). With
 * highlightMatch, the part of a label that matches what was typed stays in ink and the rest of
 * the label dims to ink-2 (Chrome's address suggestions, VS Code's quick open: the match says why
 * the option is there). Colour only, never weight: a bolder match would change the label's width
 * at every keystroke.
 *
 * The field's text is one run: a native input cannot style ranges (a host in ink, a path dimmer).
 * A display overlay is not worth its cost: see the spec's notes. */

const row = option();
const ctl = control({ kind: "field" });
const DIR = "[unicode-bidi:plaintext] [text-align:match-parent]";

export const combobox = tv({
  slots: {
    base: "inline-flex flex-col gap-1.5 min-w-0 max-w-full",
    label: "text-sm font-medium text-ink",
    /* the shared control recipe (lib/control.ts), field kind: a text field, so the ring shows for any
     * focus and stays while the list is open (focus stays in the input). The caret Button sits 2px
     * from the end. */
    control: [ctl.base(), "flex items-center ps-0 pe-0.5 cursor-text"],
    /* what sits before the text (an icon, an avatar, a status): text ink-2, icons ink-3 and 14px,
     * as far from the edge as the text would be (the size's padding), and the text 8px after it (the input
     * group's addon). Text: one line, cut at its end past 45% of the field (the adapter adds a
     * title while cut); elements: a centred row that never shrinks. A press on it is a press in the
     * field (the adapter); a control inside it (a button, a link) keeps its own */
    start: [
      "min-w-0 max-w-[45%] shrink-0 ps-(--control-px) overflow-hidden text-ellipsis whitespace-nowrap text-ink-2 [unicode-bidi:plaintext]",
      "has-[>*]:flex has-[>*]:items-center has-[>*]:gap-1.5 has-[>*]:overflow-visible has-[>*]:max-w-none [&>svg]:size-[14px] [&>svg]:shrink-0 [&>svg]:text-ink-3",
      /* the end part's mirror: beginning with a button (a site-info button, a scope picker), it sits
       * 2px from the edge, as the caret does at the end */
      "has-[>button:first-child]:ps-0.5",
    ],
    /* what sits after the text, before the caret (a bookmark star, a status, a count): the start
     * part's mirror. Text ink-2, icons ink-3 and 14px, a centred row that never shrinks; the text stops 8px before
     * it, and it keeps the size's padding from the edge (2px when it ends in a button, as the caret
     * does; the start part mirrors it). A press on it is a press in the field; a control inside it keeps its own */
    end: [
      "flex shrink-0 items-center gap-1.5 pe-(--control-px) text-ink-2 whitespace-nowrap [&>svg]:size-[14px] [&>svg]:shrink-0 [&>svg]:text-ink-3",
      "has-[>button:last-child]:pe-0.5",
    ],
    /* the control's bare input: fills it, so a click anywhere but the caret lands in the field */
    input: ctl.input(),
    /* the caret Button: its own hover and press. Open, it does not keep the ghost Button's open
     * fill: the field's ring already says the list is open, as on the select (whose caret has none) */
    trigger: "shrink-0 aria-expanded:bg-transparent aria-expanded:hover:bg-hover aria-expanded:active:bg-hover-2",
    /* carries kbd-instant: a list opened from the keyboard flips its caret at once */
    indicator: [
      "kbd-instant",
      "inline-flex text-[12px] [&>svg]:size-[1em] motion-transform-move",
      "[[data-combobox=trigger][data-state=open]_&]:rotate-180",
    ],
    positioner: "",
    /* the select's list: never narrower than the control (or 120px), then as wide as its longest
     * option, up to 360px; past that an option wraps */
    content: [popup({ drop: true }), "w-max min-w-[max(var(--reference-width,0px),120px)] max-w-[min(360px,calc(100vw-16px))]"],
    highlight: [glideLayer, "inset-x-1"],
    item: row.base(),
    /* optional leading icon (14px, ink-3), or a 14px image (a favicon) */
    itemIcon: [row.icon(), "[&>img]:size-[14px] [&>img]:rounded-[3px]"],
    itemText: row.text(),
    /* highlightMatch: the typed part of the label, in ink inside the dimmed label */
    itemMatch: "text-ink",
    itemMeta: [row.meta(), DIR],
    itemIndicator: row.indicator(),
    /* nothing matches: one quiet row (ink-2: it says why the list is empty), the height of an option */
    empty: [
      "flex items-center min-h-[var(--option-height,30px)] py-[5px] px-2 text-dense leading-[1.2] text-ink-2", DIR,
      "pointer-coarse:min-h-[max(40px,var(--option-height,30px))] pointer-coarse:text-md",
    ],
  },
  variants: {
    /* the shared control's sizes and looks; up to 28px the list's rows are 26px */
    size: {
      xs: { control: controlSize.xs, content: "[--option-height:26px]" },
      sm: { control: controlSize.sm, content: "[--option-height:26px]" },
      md: { control: controlSize.md },
      lg: { control: controlSize.lg },
    },
    variant: {
      outline: { control: controlVariant.outline },
      subtle: { control: controlVariant.subtle },
      ghost: { control: controlVariant.ghost },
    },
    /* a start part: the text begins 8px after it instead of at the size's padding. Physical sides
     * from the control's direction, as the input's own padding (its dir="auto" text must not
     * flip it) */
    start: {
      true: { input: "[:dir(ltr)>&]:pl-2 [:dir(rtl)>&]:pr-2" },
      false: {},
    },
    /* an end part: the text stops 8px before it */
    end: {
      true: {},
      false: {},
    },
    /* highlightMatch, on a label that contains what was typed: the label dims, its match stays ink */
    matching: {
      true: { itemText: "text-ink-2" },
      false: {},
    },
    /* no caret: the control ends at the text, which keeps the size's padding at its end */
    caret: {
      true: {},
      false: { control: "pe-0", input: "[:dir(ltr)>&]:pr-(--control-px) [:dir(rtl)>&]:pl-(--control-px)" },
    },
  },
  compoundVariants: [
    /* the end part holds the field's end padding; the text stops 8px before it */
    { end: true, class: { input: "[:dir(ltr)>&]:pr-2 [:dir(rtl)>&]:pl-2" } },
    /* before the caret the end part needs no padding of its own: the caret's box spaces it */
    { end: true, caret: true, class: { end: "pe-0 has-[>button:last-child]:pe-0" } },
  ],
  defaultVariants: { size: "md", variant: "outline", start: false, end: false, caret: true, matching: false },
});

export type ComboboxRecipeProps = VariantProps<typeof combobox>;
```
