Tag Input
A chip-style tag field with autocomplete suggestions, keyboard navigation, comma and paste splitting, a max limit, validation, and duplicate protection.
Overview
About the Tag Input
A chip-style tag field with autocomplete suggestions, keyboard navigation, comma and paste splitting, a max limit, validation, and duplicate protection. It is delivered as editable TypeScript for React. Tailwind CSS is not required; the component's visual CSS is embedded in its TypeScript source. Its focused API can be adapted to your own content and visual system.
Usage
When to use it
- Profile skills, topics, and labels where people add several short values.
- Filters, invites, and keyword fields that combine suggestions with free text.
What’s included
Files in the product ZIP
Tag Input source
components/tag-input.tsxEditable React and TypeScript component source.
Working example
examples/example.tsxA minimal import and render example that matches the packaged API.
Installation guide
README.mdManual ZIP installation, styling, compatibility, asset, and usage notes.
Usage
Import and render
Copy the packaged source to the documented path, then use the public API shown below.
import { TagInput } from "@/components/tag-input";export default function SkillsField() {
return <TagInput label="Skills" name="skills" suggestions={["React", "TypeScript", "Figma"]} max={5} />;
}Props
Component API
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | "Tags" | Visible field label. |
| value | string[] | — | Controlled tags. |
| defaultValue | string[] | [] | Initial tags when uncontrolled. |
| onChange | (tags: string[]) => void | — | Called when tags are added or removed. |
| suggestions | string[] | [] | Autocomplete options. |
| max | number | — | Maximum number of tags. |
| allowCustom | boolean | true | Allow tags that are not in suggestions. |
| allowDuplicates | boolean | false | Allow the same tag more than once. |
| validate | (tag: string) => string | true | — | Return an error message to reject a tag. |
| accent | string | "#a78bfa" | Chip and focus color. |
| className | string | "" | Additional root class names. |
With name set, a hidden input submits the tags as a comma-separated value.
Compatibility
Verified project setup
- ReactLoom's preview is tested with Next.js 16.3.8 App Router, React 19.2.8, TypeScript 5.9.3, and Tailwind CSS 4.3.3. This describes the store environment, not the product's minimum requirements.
- This interactive component includes the "use client" directive and must remain behind a Client Component boundary in the Next.js App Router.
- Tailwind CSS is not required; the component's visual CSS is embedded in its TypeScript source.
- Images
- No image files are included or required by the packaged component.
- Fonts
- No font files are included. The component uses system font fallbacks unless your app supplies a matching font.
Installation
Add it to your project
Download the Tag Input ZIP, place the source file at src/components/tag-input.tsx, and copy the example into your own page or feature folder.
Target path
src/components/tag-input.tsxNo additional npm runtime packages are required beyond the React host; follow the styling requirements below.
Styling requirements
- Tailwind CSS is not required by this component.
- All component styles are embedded in components/tag-input.tsx.