Skip to content
synccn

Tag Input

Type to add tags, with suggestions and a limit.

reacttailwind

Press Enter or comma to add. Up to 6 topics.

Installation

$ pnpm dlx shadcn@latest add @synccn/tag-input

First time in this project? Connect synccn with one command.

Usage

import { TagInput } from "@/components/ui/tag-input";<TagInput suggestions={topics} max={6} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

TagInput

Type and press Enter or comma to add a tag. Backspace removes the last one.

  • value
    string[]

    Controlled tags.

  • defaultValue
    string[]

    Default []

    Initial tags when uncontrolled.

  • onValueChange
    (tags: string[]) => void

    Called with the new tags.

  • placeholder
    string

    Default "Add a tag…"

    Shown when empty.

  • max
    number

    Most tags allowed.

  • suggestions
    string[]

    Default []

    Offered as the user types.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseControllable (works controlled or uncontrolled)

npm packages

Keyboard

  • Enteror,Add the typed tag
  • BackspaceRemove the last tag when the field is empty

Accessibility

  • Each tag has a remove button with an accessible label.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA attributes: aria-label
  • Keys handled: Enter, Backspace