Picker
Let people choose one item, like a project or a branch, from a searchable list behind a button.
Use a picker when people choose where or what the agent works on, from more items than fit in a row of buttons. The button shows the chosen item, and pressing it opens a search field over the list, with footer actions like New project below it.
Installation
npx shadcn@latest add @kind-ui/pickerComposition
Picker
βββ PickerTrigger
βββ PickerContent
βββ PickerList
βββ PickerSectionRows
βββ PickerRowItem
βββ PickerItemPicker is a group named by its label and the chosen item. PickerTrigger is the button, with the chosen item's icon and label, or the label while nothing is chosen. PickerContent is the popover, and PickerList is UI SDK's Command inside it: the search field, the text shown while nothing matches, and every page of rows. To arrange the list yourself, pass PickerList a function of its state that renders PickerSectionRows for each section of pages. PickerRowItem is a row, and PickerItem is its content: its icon, label, description, trailing text and a check on the chosen item.
Usage
Items
Pass items, each with a value and a label, and optionally a description (a second line under the label), meta (trailing text), an icon, keywords, a group and disabled. Groups show in the order they first appear. A disabled item stays in the list, its label dimmed and its description readable, so it can say why, and can't be chosen. Every value must be unique, on every page, and differ from every action's id.
In React, icon is an image URL or an element, like an inline <svg>. Icons render at 16px and are hidden from assistive technology, so the label names the row.
Pass value and onValueChange to control the chosen item, or defaultValue to start with one. onValueChange gets the item's value, with the reason item-press when a person chose it, or imperative from setValue. Choosing an item closes the list, unless you cancel the change with details.cancel().
Searching
Typing in the search field filters the list as you type. An item matches when its label, description or keywords hold the letters in order, and the matching letters are marked. When nothing matches, the list shows emptyText ("No matches"). Set placeholder to change the field's "Searchβ¦".
Actions
Pass actions, each with an id and a label, for footer rows after the items, like New project. They show on the first page, and the arrow keys reach them like any row. Pressing one calls onAction with its id and closes the list; cancel it with details.cancel() to keep the list open. Without onAction, the actions can't run.
<Picker
items={projects}
actions={[{ id: "new-project", label: "New project" }]}
onAction={(id) => createProject()}
/>Pages
Give an item items to make it open a page of them, marked with a chevron. The search starts empty on the new page, and a Back row (backLabel) is its footer. Backspace in the empty search field, or Escape once it's empty, goes back and puts the previous page's search back. setValue reaches an item on any page.
Keyboard
The button is one Tab stop. Enter or Space opens the list with focus in the search field. The arrow keys move the highlight, skipping disabled items, and Enter chooses. Escape clears the search, then closes the list, and focus returns to the button.
Presentation and Motion
The list opens as a popover below the button. With presentation="auto", the default, it's a bottom sheet on small touch screens instead; pass "popover" or "sheet" to choose one. The popover rises and fades in. Under prefers-reduced-motion, or with motion="reduced", it only fades, over 120 ms, and with motion="none" it opens at once.
Project
Group projects by their owner with group, and put what each is in description, which the search reaches too.
Branch
Put each branch's ahead and behind counts in meta, which sits at the end of its row, and offer New branch as an action.
API Reference
Prop
Type
Vue, Svelte and Solid take the same props. Controlled props and callbacks are spelled as each framework expects:
| React | Vue | Svelte | Solid |
|---|---|---|---|
value, onValueChange | v-model:value, @value-change | bind:value, onValueChange | value, onValueChange |
open, onOpenChange | v-model:open, @open-change | bind:open, onOpenChange | open, onOpenChange |
onAction | @action | onAction | onAction |
Agent
An agent connected with createAgent finds the picker by its label and reads open and the chosen item's value. Its setValue takes any item on any page and refuses an unknown or disabled one. run takes an action's id and is offered only while onAction is set. Neither closes the list, and neither is offered while the picker is disabled. It needs no person to confirm.
Prop
Type
Runs in React, Vue, Svelte, Solid and Web Components. On <kind-picker label="Work in" can-run>, set items, actions and value as properties, and listen for pickerchange, with the item's value as event.detail.value, pickeraction, with the action's id, and openchange. An item's icon is an image URL or an Element, which the element copies into its row. The element fills in its button and list when it has no children.