Picker
A command palette at popover scale: search, groups, hints and a footer.
Installation
pnpm add @heyramzi/uiUsage
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
optionsPickerOption<V>[]- Flat list. Mutually exclusive with `groups`.
groupsPickerGroup<V>[]- Titled runs, when the menu has a shape worth naming.
valuerequiredV | V[] | null- An array checks each row in it, and a pick leaves the menu open for the next one.
onSelectrequired(value: V) => voidtriggerrequiredSnippet- The control that opens the menu. Rendered inside `Popover.Trigger`.
triggerClassstring- Class for the trigger. Use `pickerTriggerClass` to build it.
triggerLabelstringleadSnippet<[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.
footerSnippet<[{ close: () => void }]>- Pinned under the list: a clear action, a hint, a secondary surface.
searchableboolean | "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.
searchPlaceholderstringemptyLabelstring- Default
"No matches" openbindableboolean- 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.
disabledboolean- 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
optionsrequiredPickerOption<V>[]valuerequiredV | nullonSelectrequired(value: V) => voidariaLabelrequiredstringplaceholderstring- Default
"Select" - Said by the trigger when nothing in the list is the current value.
searchPlaceholderstring- 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" classstring
| 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 |