Multi-Select

View as Markdown

Pick several from a known list, shown as chips, such as assignees.

Assignees
Ada Lovelace
Mira Patel

When to use

Pick several from a known list, shown as chips, such as assignees. Use Tag Input instead when people can type values the list doesn't hold.

Usage

import { MultiSelect } from "./ui/uicontext/components/MultiSelect.ts"
const Message = UiSchema.TaggedEnum({ ChangedTeams: { selected: Schema.Array(Schema.String) } })const teams = [	{ value: "design", label: "Design" },	{ value: "platform", label: "Platform" },	{ value: "growth", label: "Growth" },]export const Teams = (h: Html.H<typeof Message.Type>, selected: ReadonlyArray<string>) =>	MultiSelect(h, {		props: { label: "Teams", options: teams, selected },		onEmit: { RequestedSelected: ({ selected }) => Message.ChangedTeams({ selected }) },	})

Examples

A limit, and an option that's down

max counts the picks and refuses one more. A disabled option says why it can't be picked.

Regions
us-east-1
eu-central-1

Your plan deploys to three regions.

2 of 3

API reference

Props

MultiSelect props
NameTypeDescription
labelrequiredstringWhat's picked: "Assignees", "Regions".
optionsrequiredMultiSelectOption[]—
selectedrequiredstring[]The picked values, in the order picked. The caller keeps them and stores what RequestedSelected asks for.
placeholderstring—
descriptionstringA line under the field.
maxnumberThe most that can be picked; the count shows under the field.
disabledboolean—
namestringSubmits each value under this form field name.

Events

MultiSelect events
EventPayloadDescription
RequestedSelected{ selected: string[] }The values asked for, all of them: store them and pass them back as selected.

Keyboard and accessibility

KeysDoes
a letterFilter the options
Down arrow Up arrowOpen the list, then move through it
EnterPick the highlighted option, or unpick it
BackspaceIn an empty field, remove the last pick
Left arrow Right arrowMove between picks and back to the field
EscapeClose the list

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/multi-select

Source