Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Tags Input for React and Tailwind

Allows users to add tags to an input field.

React
Solid
Vue
Svelte

Installation

bunx --bun shadcn@latest add https://kit.dev/r/tags-input.json

Anatomy

TagsInputContext
├── TagsInputLabel
├── TagsInput
├── TagsInputInput
├── TagsInputClearTrigger
└── TagsInputItem
    ├── TagsInputItemPreview
    ├── TagsInputItemInput
    ├── TagsInputItemText
    └── TagsInputItemDeleteTrigger

Usage

import { Field, FieldLabel } from "@/components/ui/field";
import {
  TagsInput,
  TagsInputContext,
  TagsInputItem,
} from "@/components/ui/tags-input";
const defaultValue = ["React", "Solid", "Vue", "Svelte"];

const TagsInputDemo = () => (
  <Field className="w-full max-w-sm">
    <FieldLabel>Frameworks</FieldLabel>
    <TagsInput className="w-full" defaultValue={defaultValue}>
      <TagsInputContext>
        {({ value }) =>
          value.map((value, index) => (
            <TagsInputItem index={index} key={value} value={value}>
              {value}
            </TagsInputItem>
          ))
        }
      </TagsInputContext>
    </TagsInput>
  </Field>
);

Accessibility

KeyDescription
ArrowDown
Move down.
ArrowLeft
Move left.
ArrowRight
Move right.
Escape
Dismiss.
Backspace
Delete backward.
Delete
Delete.
Enter
Activate the focused item.
Space
Activate the focused control.

Demos

Blur Behavior

Combobox

Controlled

Controlled Input Value

Custom Delimiter

Disable Editing

Disabled

Field

Invalid

Max Length

Max Tags

Max With Overflow

Paste Behavior

Sanitize Value

Size Lg

Size Md

Size Sm

Validation

API Reference

TagsInputContext

div

PropType

TagsInput

div

PropType
AttributeType

TagsInputInput

input

PropType
AttributeType

TagsInputClearTrigger

button

PropType
AttributeType

TagsInputItem

div

PropType
AttributeType

TagsInputItemPreview

div

PropType
AttributeType

TagsInputItemInput

input

PropType
AttributeType

TagsInputItemText

span

PropType
AttributeType

TagsInputItemDeleteTrigger

button

PropType
AttributeType
CSS variableType

TagsInputControl

div

PropType
AttributeType

TagsInputRootProvider

div

PropType
AttributeType

useTagsInput

PropType

TagsInputContext

PropType