Tag v0.1.0 Data display

Chip for filters and selections, optionally dismissible.

import { Tag } from "latticeui-react";

Examples

Tones

designreactdeprecated
Show code
<Tag>design</Tag>
<Tag tone="accent">react</Tag>
<Tag tone="danger">deprecated</Tag>

Dismissible

reactvuesveltesolid
Show code
const [tags, setTags] = useState(["react", "vue", "svelte"]);

{tags.map((tag) => (
  <Tag key={tag} tone="accent" onDismiss={() => setTags(tags.filter((t) => t !== tag))}>
    {tag}
  </Tag>
))}

Anatomy

These data-part attributes are a versioned public API - style and test against them; they will not change in a minor release.

PartElementStable selector
rootspan[data-scope="tag"][data-part="root"]
labelspan[data-scope="tag"][data-part="label"]
closebutton[data-scope="tag"][data-part="close"]

Props

PropTypeDefaultDescription
tone"neutral" | "accent" | "danger""neutral"
onDismiss() => voidRenders a labelled remove button when set.

Accessibility

Roles:

KeyAction
Enter / Spaceactivates the remove button

Styling

Override styles by targeting the stable selectors below from any unlayered CSS - it always beats the library's @layer latticeui styles, no !important needed.

[data-scope="tag"][data-part="root"] {
  /* your overrides */
}

Component tokens: --tag-bg--tag-fg

State attributes: data-tone