Tag input
Tags typed in: a separator or Enter ends one, a paste is split, Backspace removes the last.
import { TagInput } from "@forgeron/ui";- ada@example.com
- not-an-email, not valid
import { TagInput } from "@forgeron/ui";
import { useState } from "react";
const email = (tag: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(tag);
export default function Emails() {
const [to, setTo] = useState(["ada@example.com", "not-an-email"]);
return (
<TagInput
label="Recipients"
placeholder="Type or paste addresses"
value={to}
onChange={setTo}
validate={email}
/>
);
}- good first issue
import { TagInput } from "@forgeron/ui";
export default function Labels() {
return (
<TagInput
label="Labels"
placeholder="Add a label, then Enter"
separators={/[,;\n]+/}
defaultValue={["good first issue"]}
max={5}
/>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the field for assistive technology. |
value / defaultValue | string[] | — | Controlled or not. |
onChange | (value: string[]) => void | — | On every change. |
separators | RegExp | /[\s,;]+/ | What ends a tag, typed or pasted. Use /[,;\n]+/ for tags with spaces. |
validate | (tag) => boolean | — | A tag that fails is marked and announced, and kept. |
max | number | — | At most this many tags. |
allowDuplicates | boolean | false | The same tag twice. |
placeholder | string | — | Shown while there is no tag. |
disabled | boolean | — | Not editable. |
id / aria-describedby / aria-invalid | string / string / boolean | — | From `Field`'s function form: the label, hint and error stay tied. |
className | string | — | Extra classes. |