Skip to content
Get started

Components

Tag

Unstable: a filter chip or a removable token, 32 px and fully rounded, that toggles with a check and removes with its own named button. Import it from @nizivo/react/unstable/tag.

Server component, no client JSUnstable

Examples

Basic

The states: a removable token, a filter on and off, and a disabled one.

CeramicsCeramics
import type { JSX } from 'react';
import { Tag } from '@nizivo/react/unstable/tag';

export function TagExample(): JSX.Element {
  return (
    <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
      <Tag label="Ceramics" removable />
      <Tag label="Ceramics" selected removable />
      <Tag label="Glassware" selected={false} />
      <Tag label="Ceramics" removable disabled />
    </div>
  );
}

Import

import { Tag } from '@nizivo/react/unstable/tag';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/tag.css';

Static or interactive

Server. No client JavaScript: its buttons call onToggle and onRemove. How to choose.

Filter or token

With selected the tag is a filter: a button with aria-pressed that shows a check when on, so the state is not colour alone. Without it, the label is plain text. removable adds a 24 px remove button named "Remove Ceramics" (labels.remove, with {label}); the two are sibling buttons. For read-only status, use Badge; for a set of choices in a form, use ChipGroup.

Props

Server component Renders data-slot="tag" with the class nz-tag. Props: TagProps. Source: src/unstable/tag/tag.tsx.

NameTypeDefaultDescription
disabledbooleanfalse
labelrequiredstring–

What the tag says: "Ceramics".

labelsPartial<TagLabels>–
onRemove() => void–

The remove button calls it.

onToggle() => void–

The toggle calls it, when selected is given.

removablebooleanfalse

Adds the remove button.

renderRenderProp<Record<string, never>>–

Must render a <span>.

selectedboolean–

A filter: whether it is on. Leave it out for a token that does not toggle.

  • Also takes every attribute of <span> except children; onToggle is redeclared above. (Omit<ComponentPropsWithRef<"span">, "children">)

render takes an element, or, in client code, a function of the props and no state.

Other exports

TagLabels type

import type { TagLabels } from '@nizivo/react/unstable/tag'

Tag's own strings (§16.4): serialisable, English defaults.

NameTypeDefaultDescription
removerequiredstring'Remove {label}'

The remove button's name: {label} is the tag's.

TagProps type

import type { TagProps } from '@nizivo/react/unstable/tag'

The props of Tag, listed above.

Data attributes and slots

Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.

SlotRendered byData attributes
tag
.nz-tag
Tag
root (takes render)
  • data-disabled (present or absent) ← disabled
    Mirrors the disabled attribute
  • data-selected (present or absent) ← selected
    Selected
tag-label
.nz-tag-label
Tag
inner element (CSS only)
none
tag-remove
.nz-tag-remove
Tag
inner element (CSS only); interactive, focus: self
none
tag-toggle
.nz-tag-toggle
Tag
inner element (CSS only); interactive, focus: self
none

CSS hooks

Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.

This stylesheet reads no public hook.

Layers: nz.components. Classes: .nz-tag, .nz-tag-check, .nz-tag-label, .nz-tag-remove, .nz-tag-toggle.

Tokens this stylesheet reads (24)

--nz-bg-brand-subtle, --nz-bg-disabled, --nz-bg-hover, --nz-bg-surface, --nz-border-brand, --nz-border-default, --nz-border-strong, --nz-border-subtle, --nz-border-width-default, --nz-duration-fast, --nz-easing-standard, --nz-font-label-m, --nz-icon-secondary, --nz-radius-full, --nz-size-icon-sm, --nz-space-1-5, --nz-space-2, --nz-space-3, --nz-space-6, --nz-space-8, --nz-text-brand, --nz-text-disabled, --nz-text-primary, --nz-text-secondary

Accessibility

These parts are interactive. Each gets the focus outline and touch-action rule from @nizivo/react/css/base.css (the nz.base layer), so the floor survives a restyle:

  • tag-remove: draws the focus outline itself on keyboard focus.
  • tag-toggle: draws the focus outline itself on keyboard focus.

Keyboard

To be written.

On this page