Select

One value from a list, chosen by a person or an agent.

Source
$npx @dinachi/cli@latest add select
Region
placeholder
SelectFieldLabel
groups
showIndicator
alignItemWithTrigger
disabled

Usage

import {
  Select,
  SelectContent,
  SelectFieldLabel,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select"

const regions = [
  { value: "fra", label: "Frankfurt" },
  { value: "lhr", label: "London" },
  { value: "nrt", label: "Tokyo" },
]

export function RegionPicker() {
  return (
    <Select items={regions}>
      <SelectFieldLabel>Region</SelectFieldLabel>
      <SelectTrigger>
        <SelectValue placeholder="Choose a region" />
      </SelectTrigger>
      <SelectContent>
        {regions.map((r) => (
          <SelectItem key={r.value} value={r.value}>
            {r.label}
          </SelectItem>
        ))}
      </SelectContent>
    </Select>
  )
}

Examples

region = "lhr"
Hold the value in state to read it or reset it.
import * as React from "react"
import { Button } from "@/components/ui/button"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"

const regions = [
  { value: "fra", label: "Frankfurt" },
  { value: "lhr", label: "London" },
  { value: "iad", label: "Virginia" },
  { value: "pdx", label: "Oregon" },
  { value: "sin", label: "Singapore" },
  { value: "nrt", label: "Tokyo" },
]

export function Example() {
  const [region, setRegion] = React.useState<string | null>("lhr")
  return (
    <div className="flex items-center gap-2">
      <Select items={regions} value={region} onValueChange={setRegion}>
        <SelectTrigger aria-label="Region">
          <SelectValue placeholder="Choose a region" />
        </SelectTrigger>
        <SelectContent>
          {regions.map((r) => (
            <SelectItem key={r.value} value={r.value}>{r.label}</SelectItem>
          ))}
        </SelectContent>
      </Select>
      <Button variant="ghost" onClick={() => setRegion(null)}>Clear</Button>
    </div>
  )
}

Notes

Clipped popups

SelectContent renders in place by default, so it inherits the stacking of an open Dialog or Drawer. Pass portal when an ancestor clips it with overflow: hidden.

API

items
agent
{ value, label }[]
Labels for each value. The trigger shows them and the agent reads them.
valueValue | null
Controlled value.
defaultValueValue | null = null
Starting value when uncontrolled.
onValueChange
agent
(value, details) => void
Runs for people and agents. details.cancel() refuses the change.
openboolean
Controlled open state.
onOpenChange
agent
(open, details) => void
Runs when the list opens or closes, from either side.
multiple
agent
boolean = false
Holds an array of values. Agents also get setValue.
disabled
agent
boolean = false
Blocks people and agents.
readOnly
agent
boolean = false
Opens to look, refuses any change.
namestring
Submits the value with a form.
requiredboolean = false
Must have a value before the form submits.
modalboolean = true
Locks page scroll and outside clicks while open.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as select.

Reads

label

The SelectFieldLabel, or the trigger's aria-label.

value

The chosen label, a list of labels when multiple, or null.

open

Whether the list is showing.

items

Every option's label, when open or passed as items.

disabled

True when the whole select is blocked.

Actions

select("Tokyo")

Picks by label, then by value. A miss lists the options.

open() / close()

Whichever fits the current state.

setValue(["Tokyo", "London"])

Replaces the whole list. Only when multiple.

An agent's change runs through onValueChange like anyone's. isAgentChange(details) is true for it, and details.cancel() refuses it; the agent is told the app refused. Disabled items, a disabled select and readOnly refuse on their own.

await agent.act({
  steps: [{ ref: "Region", action: "select", args: ["Tokyo"] }],
})

Accessibility

  • The trigger is a button with a listbox popup; items are options with their selected state exposed.
  • Give every select a name: a SelectFieldLabel, or aria-label on the trigger. The agent reads the same name.
  • Disabled items stay announced but are skipped by the keyboard.
  • Focus returns to the trigger when the list closes.