Pick one option from a list you can filter by typing.
- 6.9 kB JS 3.7 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Installs in a fresh app
- 5 keys checked
- Right-to-left
- 2 tests
StatusPriorityAssignee
Backlog
Todo
In progress
In review
Done
Canceled
–No priority
Urgent
High
Medium
Low
Maya Chen
Omar Haddad
Scout (agent)
import { UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Picker } from "./ui/uicontext/components/Picker.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"import { people, priorities, statuses, unassigned } from "./options.ts"const styles = stylex.create({ // a properties panel: a label column and a picker column panel: { display: "grid", gridTemplateColumns: "6rem minmax(0, 1fr)", alignItems: "center", columnGap: space.md, rowGap: space.xs, inlineSize: "min(100%, 20rem)", }, label: { fontSize: font.sm, color: color.muted },})const Message = UiSchema.TaggedEnum({ PickedStatus: { value: Schema.String }, PickedPriority: { value: Schema.String }, PickedAssignee: { value: Schema.String },})export const IssueProperties = Html.component({ name: "IssueProperties", model: Schema.Struct({ status: Schema.String, priority: Schema.String, assignee: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ status: "doing", priority: "high", assignee: null }), update: { PickedStatus: ($, { value }) => $.evolve({ status: value }), PickedPriority: ($, { value }) => $.evolve({ priority: value }), PickedAssignee: ($, { value }) => $.evolve({ assignee: value }), }, view: (h, model) => h.div.attrs(sx(styles.panel)).children( h.span.attrs(sx(styles.label)).children("Status"), Picker(h, { key: "status", props: { agentId: "issue-eng-142-status", name: "Status", options: statuses, selected: model.status, empty: statuses[0]! }, onEmit: { RequestedChange: ({ value }) => Message.PickedStatus({ value }) }, }), h.span.attrs(sx(styles.label)).children("Priority"), Picker(h, { key: "priority", props: { agentId: "issue-eng-142-priority", name: "Priority", options: priorities, selected: model.priority, empty: priorities[0]! }, onEmit: { RequestedChange: ({ value }) => Message.PickedPriority({ value }) }, }), h.span.attrs(sx(styles.label)).children("Assignee"), Picker(h, { key: "assignee", props: { agentId: "issue-eng-142-assignee", name: "Assignee", options: people, selected: model.assignee, empty: unassigned }, onEmit: { RequestedChange: ({ value }) => Message.PickedAssignee({ value }) }, }), ),})When to use
Pick one option from a list you can filter by typing. Use Multi-Select instead when people pick more than one.
Usage
import { Picker } from "./ui/uicontext/components/Picker.ts"const Message = UiSchema.TaggedEnum({ PickedStatus: { value: Schema.String } })export const StatusPicker = (h: Html.H<typeof Message.Type>, status: string) => Picker(h, { props: { name: "Status", options: statuses, selected: status, empty: statuses[0]! }, onEmit: { RequestedChange: ({ value }) => Message.PickedStatus({ value }) }, })Examples
Compact, in a list
With compact only the glyph shows, for a row's status or priority. Its accessible name still says the property and its value.
–No priority
Urgent
High
Medium
Low
Backlog
Todo
In progress
In review
Done
Canceled
–No priority
Urgent
High
Medium
Low
Backlog
Todo
In progress
In review
Done
Canceled
–No priority
Urgent
High
Medium
Low
Backlog
Todo
In progress
In review
Done
Canceled
import { UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Picker } from "./ui/uicontext/components/Picker.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, corner, font, space } from "./ui/uicontext/components/tokens.stylex.ts"import { priorities, statuses } from "./options.ts"const styles = stylex.create({ list: { display: "grid", inlineSize: "min(100%, 30rem)", borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card }, row: { display: "flex", // a grid item sizes to its nowrap title unless told it may be narrower minInlineSize: 0, alignItems: "center", gap: space.xs, paddingInline: space.md, minBlockSize: 40, borderTopWidth: { default: 1, ":first-child": 0 }, borderTopStyle: "solid", borderTopColor: color.line, }, id: { flexShrink: 0, inlineSize: "4.5rem", fontSize: font.sm, color: color.faint }, title: { flexGrow: 1, minInlineSize: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontSize: font.base },})const Issue = Schema.Struct({ id: Schema.String, title: Schema.String, status: Schema.String, priority: Schema.String })type Issue = typeof Issue.Typeconst issues: ReadonlyArray<Issue> = [ { id: "ENG-142", title: "Sign-in link expires before the email arrives", status: "doing", priority: "urgent" }, { id: "ENG-139", title: "Export to CSV drops the last row", status: "todo", priority: "medium" }, { id: "ENG-131", title: "Webhook retries ignore the backoff setting", status: "review", priority: "low" },]const Message = UiSchema.TaggedEnum({ PickedStatus: { id: Schema.String, value: Schema.String }, PickedPriority: { id: Schema.String, value: Schema.String },})export const IssueRows = Html.component({ name: "IssueRows", model: Schema.Struct({ issues: Schema.Array(Issue) }), message: Message,}).make({ init: () => ({ issues }), update: { PickedStatus: ($, { id, value }) => $.evolve({ issues: (list) => list.map((i) => (i.id === id ? { ...i, status: value } : i)) }), PickedPriority: ($, { id, value }) => $.evolve({ issues: (list) => list.map((i) => (i.id === id ? { ...i, priority: value } : i)) }), }, view: (h, model) => h.div.attrs(sx(styles.list)).children( model.issues.map((issue) => h.div.key(issue.id).attrs(sx(styles.row)).children( // compact: only the glyph shows; the name and value are its accessible name Picker(h, { key: `priority:${issue.id}`, props: { agentId: `priority:${issue.id}`, name: "Priority", options: priorities, selected: issue.priority, empty: priorities[0]!, compact: true }, onEmit: { RequestedChange: ({ value }) => Message.PickedPriority({ id: issue.id, value }) }, }), h.span.attrs(sx(styles.id)).children(issue.id), Picker(h, { key: `status:${issue.id}`, props: { agentId: `status:${issue.id}`, name: "Status", options: statuses, selected: issue.status, empty: statuses[0]!, compact: true }, onEmit: { RequestedChange: ({ value }) => Message.PickedStatus({ id: issue.id, value }) }, }), h.span.attrs(sx(styles.title)).children(issue.title), )), ),})Read-only and disabled
readOnly opens the list to show the choices without picking; disabled doesn't open at all.
StatusAssignee
Backlog
Todo
In progress
In review
Done
Canceled
Maya Chen
Omar Haddad
Scout (agent)
import { UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Picker } from "./ui/uicontext/components/Picker.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"import { people, statuses, unassigned } from "./options.ts"const styles = stylex.create({ panel: { display: "grid", gridTemplateColumns: "6rem minmax(0, 1fr)", alignItems: "center", columnGap: space.md, rowGap: space.xs, inlineSize: "min(100%, 20rem)", }, label: { fontSize: font.sm, color: color.muted },})const Message = UiSchema.TaggedEnum({ PickedStatus: { value: Schema.String } })export const LockedProperties = Html.component({ name: "LockedProperties", model: Schema.Struct({}), message: Message,}).make({ init: () => ({}), update: { PickedStatus: ($) => $.model }, view: (h) => h.div.attrs(sx(styles.panel)).children( h.span.attrs(sx(styles.label)).children("Status"), // a guest can open the list to see the choices, but not pick one Picker(h, { key: "status", props: { agentId: "locked-status", name: "Status", options: statuses, selected: "review", empty: statuses[0]!, readOnly: true }, onEmit: { RequestedChange: ({ value }) => Message.PickedStatus({ value }) }, }), h.span.attrs(sx(styles.label)).children("Assignee"), // the issue is archived: nothing to open Picker(h, { key: "assignee", props: { agentId: "locked-assignee", name: "Assignee", options: people, selected: "omar", empty: unassigned, disabled: true }, onEmit: { RequestedChange: ({ value }) => Message.PickedStatus({ value }) }, }), ),})API reference
Props
| Name | Type | Description |
|---|---|---|
agentId | string | This picker's id for agents, unique on the page: "issue-ENG-12-status" |
agent | boolean | False when the picker sits inside a component whose own contract already exposes this value (a list's cell editor): the picker then registers no contract, so agents see one entry, not two |
namerequired | string | What the property is, for the filter's placeholder and screen readers: "Status" |
optionsrequired | PickerOption[] | The choices, each with a value, a label and a glyph. |
selectedrequired | string | null | The picked option's value, or null for none. The caller keeps it. |
emptyrequired | PickerOption | Shown on the button when nothing is selected |
compact | boolean | An icon-only button (a row in a list), or the full row with its label (a properties panel) |
disabled | boolean | The value can't be changed or the list opened, as when the plan or a permission rules it out |
readOnly | boolean | The list opens to show the choices, but none can be picked: someone else owns the value |
Events
| Event | Payload | Description |
|---|---|---|
RequestedChange | { value: string } | The person or an agent picked an option; store its value and pass it back as selected |
Agent actions
| Action | Description |
|---|---|
PickedOption | Choose one of the choices by its value (see page_query) |
Keyboard and accessibility
| Keys | Does |
|---|---|
| EnterEnter SpaceSpace ↓Down arrow | Open the list |
| a letter | Filter the options |
| ↓Down arrow ↑Up arrow | Move the highlight |
| EnterEnter | Pick the highlighted option |
| EscEscape | Close without picking |
- The trigger is a button that names the field and its value, such as "Status: In progress". Opening it puts focus in a filter field over the list.
- Typing filters, the arrow keys move, Enter picks and Escape closes; the chosen option is marked checked.
- Agents read the current value and the choices, and pick one by value.
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/combobox