Installation
npx logic2b@next add tags-inputUsage
import { TagsInput } from "@/components/ui/tags-input"
const [tags, setTags] = React.useState<string[]>([])
<TagsInput
value={tags}
onValueChange={setTags}
placeholder="Add a tag…"
/>
Enter or comma commits the draft, pasted comma-separated text is split into tags, Backspace on an empty field removes the last tag, and blur commits whatever is pending. Duplicates are ignored.
Examples
Max tags
Cap the list with max — extra pasted values are dropped and the field
disables until a tag is removed.
Accessibility
- The editable part is a real
<input>: label it with<Label htmlFor>(theidis forwarded) oraria-label. - Each chip’s close button exposes
aria-label="Remove <tag>". - Backspace on an empty field removes the last tag, so the whole control works without a pointer.
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
<TagsInput
defaultValue={["registry", "accessible"]}
placeholder="Add a tag…"
max={5}
aria-label="Component tags"
/>API reference
Generated from the public TypeScript exports in src/ui/tags-input.tsx.
TagsInput
ComponentTags input — free-form multi-value entry rendered as removable chips. Enter or comma commits the draft, paste splits on commas, Backspace on an empty draft removes the last tag. Duplicates are ignored; `max` caps the list.
Props: Omit<React.ComponentProps<"div">, "defaultValue" | "onChange"> & { value?: string[] defaultValue?: string[] onValueChange?: (value: string[]) => void placeholder?: string max?: number disabled?: boolean }| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
value | string[] | No | — | — |
defaultValue | string[] | No | — | — |
onValueChange | (value: string[]) => void | No | — | — |
placeholder | string | No | — | — |
max | number | No | — | — |
disabled | boolean | No | — | — |
Accessibility contract
Machine-readable behavior and consumer responsibilities for tags-input.
- Support
- Authored behavior
- Pattern
- multi-value textbox
- HTMLInputElement
| Keys | Behavior |
|---|---|
| Enter , | Commit the current text as a tag. |
| Backspace | Remove the last tag when the text field is empty. |
Built-in semantics
- The editable input receives id/aria-label/aria-labelledby; removal buttons name their tag.
Consumer responsibilities
- Provide a visible label and announce additions/removals in application context when that feedback is important.