Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Tags Input

A text field that turns what is typed into tags, each a chip with a button that removes it.

Built on the headless Tags Input.See its API in Docs

Rendered by React 19.3.1

tags-input.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/tags-input.json

It also adds utils, button. The app needs its setup first: Installation.

Usage

Put a TagsInputList and a TagsInputInput inside TagsInput, and render one TagsInputTag per entry of the value inside the list, each holding a TagsInputTagContent with a TagsInputTagText and a TagsInputTagRemove. Add a TagsInputTagEditInput to the content to let a tag be edited in place under editable, and a TagsInputClear named with aria-label to remove every tag. Name the list with aria-label, or put the field in a Field whose label names it. Enter and the delimiters (a comma by default) add a tag; adding, refusing, removing, editing, the keyboard and the announcements come from the headless Tags Input.

import {
  TagsInput,
  TagsInputClear,
  TagsInputInput,
  TagsInputList,
  TagsInputTag,
  TagsInputTagContent,
  TagsInputTagEditInput,
  TagsInputTagRemove,
  TagsInputTagText,
} from '@/components/ui/tags-input'

Examples

Default

Three topics in the field's box, each with its remove button, and the input after them.

Its preview and code are at the top of the page.

Editable

Tags edited in place with Enter, a refused duplicate, and a Clear at the box's end.

Rendered by React 19.3.1

tags-input-editable.tsx

The Root is the Input's box: it is ringed while the input has focus and turns destructive while an entry is refused or the field is invalid. A tag is a chip whose remove button is the Button's ghost icon-xs, 24 by 24 CSS pixels, so it meets the target size of WCAG 2.5.8. A disabled tag is dashed and unfilled rather than only greyed, and a focused tag rings its chip. While a tag is edited its text gives way to an input as wide as the text, in the same chip. This item takes Base UI's component ID as its slug and one name per Base UI part.

API reference

The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Tags Input's API reference.