Type free-text tags; Enter or a comma adds one, and pasting a list adds them all.
$ pnpm dlx shadcn@latest add https://dashral.com/r/tag-input.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/tag-input.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/tag-inputUsage
import { TagInput } from "@/components/dashral/tag-input"
<TagInput label="Tags" defaultValue={["design", "frontend"]} maxTags={5} />Examples
With validation
validate refuses a tag with a message, e.g. anything that isn't an email.
API reference
TagInput
Also takes every prop of <input>(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
value / defaultValue | string[]Controlled or initial tags. | [] |
onValueChange | (value: string[]) => voidCalled with the new value. | — |
maxTags | numberAt most this many. | — |
validate | (tag: string) => string | nullReturn a message to refuse a tag. | — |
separators | string[]Characters that finish a tag (Enter always does); pasted text is split on them. | [","] |
placeholder | string | "Add a tag…" |
label | ReactNodeShown above, linked to the control. | — |
description | ReactNodeA hint under the control. | — |
error | boolean | ReactNodetrue shows the error style; a message also shows under the control. | — |
labelAction | ReactNodeAt the end of the label's row, e.g. a “Forgot password?” link or the current value. | — |
withAsterisk | booleanMarks the label with an asterisk, e.g. alongside required. | false |
classNames | { root, label, description, error, box }Classes for each part. | — |
Keyboard
| Keys | Action |
|---|---|
| EnterorComma | Add what's typed |
| Backspace | In the empty field: take the last tag back to edit it |
| Tab | Reach each tag's remove button |
Accessibility
- Tags are a labelled list; remove buttons name their tag; a refused tag's message is an alert linked to the field.