Tag Input

Type, then Enter or a comma to add a tag; suggestions, checks for duplicates and emails, and pasting a list.

Labels
bug
checkout

Enter or a comma adds one. Paste a list to add several.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/tag-input

Usage

import { TagInput } from "./ui/uicontext/components/TagInput.ts"
const Message = UiSchema.TaggedEnum({ RequestedLabels: { tags: Schema.Array(Schema.String) } })export const LabelsField = (h: Html.H<typeof Message.Type>, labels: ReadonlyArray<string>) =>	TagInput(h, {		props: { label: "Labels", tags: labels, suggestions: ["bug", "design", "docs"] },		onEmit: { RequestedTags: ({ tags }) => Message.RequestedLabels({ tags }) },	})

Examples

Invite by email

Addresses are checked as they're added, and a long one shortens in its chip. Try pasting “[email protected], not-an-email”.

API reference

Props

TagInput props
NameTypeDescription
labelrequiredstringWhat the tags are: "Labels", "Invite by email".
tagsrequiredstring[]The tags so far. The caller keeps them and stores what RequestedTags asks for.
suggestionsstring[]Tags to offer as you type: the labels a workspace already has, the people you work with.
suggestionsOnlybooleanOnly suggestions can be added, not new text: a fixed set of labels.
kind"text" | "email"email checks each tag is an address and opens the email keyboard on a phone.
maxnumberThe most tags allowed.
placeholderstring—
descriptionstringA line under the field.
disabledboolean—
namestringSubmits each tag under this form field name.

Events

TagInput events
EventPayloadDescription
RequestedTags{ tags: string[] }The tags asked for, all of them: store them and pass them back as tags.

Source