Dice UI

Tags Input

Display a list of tags in an input field with the ability to add, edit, and remove them.

API

Installation

pnpm add @diceui/tags-input

Installation with shadcn/ui

pnpm dlx shadcn@latest add @diceui/tags-input

Layout

Import the parts, and compose them together.

import {
  TagsInput,
  TagsInputLabel,
  TagsInputItem,
  TagsInputItemText,
  TagsInputItemDelete,
  TagsInputInput,
  TagsInputClear,
} from "@diceui/tags-input";
 
return (
  <TagsInput>
    <TagsInputLabel/>
    <TagsInputItem >
      <TagsInputItemText />
      <TagsInputItemDelete />
    </TagsInputItem>
    <TagsInputInput />
    <TagsInputClear />
  </TagsInput>
)

Examples

Editable

With Validation

Validate the input value before adding it to the list. Can be used to prevent duplicate tags.

With Sortable

TagsInput can be composed with Sortable to allow reordering of tags.

API Reference

TagsInput

Container for the tags input.

Prop

Type

Data AttributeValue
[data-disabled]Present when disabled.
[data-invalid]Present when invalid.
[data-readonly]Present when readOnly.

TagsInputLabel

Label element for the tags input.

Prop

Type

Data AttributeValue
[data-disabled]Present when disabled.

TagsInputInput

Text input for adding new tags.

Prop

Type

Data AttributeValue
[data-invalid]Present when invalid.

TagsInputItem

Individual tag item.

Prop

Type

Data AttributeValue
[data-state]"active" | "inactive"
[data-highlighted]Present when highlighted.
[data-disabled]Present when disabled.
[data-editing]Present when being edited.
[data-editable]Present when the tags input is editable.

TagsInputItemText

Text content of a tag.

Prop

Type

TagsInputItemDelete

Button to remove a tag.

Prop

Type

Data AttributeValue
[data-disabled]Present when disabled.
[data-state]"active" | "inactive"

TagsInputClear

Button to clear all tags.

Prop

Type

Data AttributeValue
[data-disabled]Present when disabled.
[data-state]"visible" | "invisible"

Accessibility

Keyboard Interactions

KeyDescription
DeleteWhen a tag is highlighted, removes it and sets focus to the next tag.
BackspaceWhen a tag is highlighted, removes it and sets focus to the previous tag. If there is no previous tag, focus moves to the next tag or input.
ArrowLeftHighlights the previous tag. When cursor is at start of input, moves focus to the last tag.
ArrowRightHighlights the next tag. When cursor is at start of input, moves focus to the first tag.
HomeHighlights the first tag in the list.
EndHighlights the last tag in the list.
EnterWhen input has text, adds a new tag. When a tag is highlighted and editable is enabled, enters edit mode.
EscapeClears tag highlight and edit mode, resets cursor to start.
TabWhen `addOnTab` is enabled and input has text, adds a new tag. Otherwise, blurs the input.

On this page