Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Picker

A command palette at popover scale: search, groups, hints and a footer.

Installation

pnpm add @heyramzi/ui

Usage

import { Picker, pickerTriggerClass } from "@heyramzi/ui/components/picker";
<Picker
  options={[{ value: "high", label: "High", hint: "P1" }]}
  {value}
  onSelect={(next) => (value = next)}
  triggerClass={pickerTriggerClass()}
>
  {#snippet trigger()}
    {selected?.label ?? "Priority"}
  {/snippet}
</Picker>

Keyboard and accessibility

Key Does
Space Enter On the trigger, opens the menu.
Arrow Down Arrow Up Moves the highlight. It loops.
Home End Moves the highlight to the first or last option.
Enter Picks the highlighted option and closes the menu.
Esc Closes the menu and returns focus to the trigger.
  • The search box shows from 7 options up, and typing filters on the label, the hint and the keywords.
  • Under 7 options there's no search box. Focus goes to the list, and typing a letter jumps to the next option that starts with it.
  • With an array for value, Enter ticks or clears the highlighted option and the menu stays open.
  • triggerLabel names the trigger. Make it say the field and its value, like "Priority: High".

API reference

Picker

options PickerOption<V>[]
Flat list. Mutually exclusive with `groups`.
groups PickerGroup<V>[]
Titled runs, when the menu has a shape worth naming.
value required V | V[] | null
An array checks each row in it, and a pick leaves the menu open for the next one.
onSelect required (value: V) => void
trigger required Snippet
The control that opens the menu. Rendered inside `Popover.Trigger`.
triggerClass string
Class for the trigger. Use `pickerTriggerClass` to build it.
triggerLabel string
lead Snippet<[PickerOption<V>]>
A mark drawn at the head of a row when the option carries no icon: an avatar, a client logo, a colour swatch.
footer Snippet<[{ close: () => void }]>
Pinned under the list: a clear action, a hint, a secondary surface.
searchable boolean | "auto"
Default "auto"
Search field. `auto` shows it from seven rows, the point at which the eye stops finding a name faster than the fingers can type it.
searchPlaceholder string
emptyLabel string
Default "No matches"
open bindable boolean
Default false
align "start" | "center" | "end"
Default "start"
width "sm" | "default" | "lg"
Default "default"
`sm` fits a word, `default` a name, `lg` a name and a date.
disabled boolean
Default false
Prop Type Default
options

Flat list. Mutually exclusive with `groups`.

PickerOption<V>[]
groups

Titled runs, when the menu has a shape worth naming.

PickerGroup<V>[]
value required

An array checks each row in it, and a pick leaves the menu open for the next one.

V | V[] | null
onSelect required (value: V) => void
trigger required

The control that opens the menu. Rendered inside `Popover.Trigger`.

Snippet
triggerClass

Class for the trigger. Use `pickerTriggerClass` to build it.

string
triggerLabel string
lead

A mark drawn at the head of a row when the option carries no icon: an avatar, a client logo, a colour swatch.

Snippet<[PickerOption<V>]>
footer

Pinned under the list: a clear action, a hint, a secondary surface.

Snippet<[{ close: () => void }]>
searchable

Search field. `auto` shows it from seven rows, the point at which the eye stops finding a name faster than the fingers can type it.

boolean | "auto" "auto"
searchPlaceholder string
emptyLabel string "No matches"
open bindable boolean false
align "start" | "center" | "end" "start"
width

`sm` fits a word, `default` a name, `lg` a name and a date.

"sm" | "default" | "lg" "default"
disabled boolean false

MarkPicker

options required PickerOption<V>[]
value required V | null
onSelect required (value: V) => void
ariaLabel required string
placeholder string
Default "Select"
Said by the trigger when nothing in the list is the current value.
searchPlaceholder string
Default "Search"
The search field's own prompt, on a list long enough to show one.
shape "square" | "circle"
Default "square"
`circle` for a face or an avatar, `square` for a logo.
width "sm" | "default" | "lg"
Default "lg"
class string
Prop Type Default
options required PickerOption<V>[]
value required V | null
onSelect required (value: V) => void
ariaLabel required string
placeholder

Said by the trigger when nothing in the list is the current value.

string "Select"
searchPlaceholder

The search field's own prompt, on a list long enough to show one.

string "Search"
shape

`circle` for a face or an avatar, `square` for a logo.

"square" | "circle" "square"
width "sm" | "default" | "lg" "lg"
class string