Skip to content

Tag

Tag

A compact label (a "chip") for a keyword, category or filter, optionally dismissible.

- The dismiss button is a real <button type="button"> wired to onDismiss. Its accessible name is dismissLabel plus the tag's text (its children; not media, icon or secondaryText): "Dismiss Cherry", so a row of tags has distinguishable dismiss buttons. Enter, Space, Delete and Backspace on it dismiss the tag (a held key dismisses once), and so do Delete and Backspace on a link in the tag's text.
- dismissIcon replaces only the icon inside that button (see TagOwnProps.dismissIcon).
- The look: appearance (filled, outline or brand), size (28, 24 or 20px tall), shape (circular or rounded) and the look-only selected, rendered as data-appearance, data-size, data-shape and data-selected. disabled dims the tag and disables its dismiss button natively (data-disabled).
- Slots before and under the text: media (an Avatar, sized for the tag), a decorative icon and a second line, secondaryText.
- In a TagGroup, a tag takes the group's size, appearance, shape and dismissible unless it sets its own, is disabled with the group, reports its dismissal to the group's onDismiss(value), and is a list item in a role="list" group.
- Polymorphic: as="a" renders a link chip with anchor props type-checked. A dismissible link chip puts the link in the content, <Tag dismissible><a href>…</a></Tag>: a dismiss button cannot sit inside a link.

**Focus after dismissal.** A tag cannot keep focus once you remove it. In a TagGroup, focus moves to the next tag for you (else the previous one, else the group's fallbackFocusRef). For a standalone tag, move focus to the next tag's dismiss button, else the previous one, else a nearby control, then remove the tag: the neighbour stays mounted, so you can focus it in onDismiss before removing the tag.

Examples

Default

Tag label
export const Default: Story = {};

Dismissible

Dismissible tag
export const Dismissible: Story = {
  args: {
    children: 'Dismissible tag',
    dismissible: true,
    onDismiss: fn(),
  },
  render: (args) => <DismissibleTag {...args} />,
};

Filter Group

export const FilterGroup: Story = {
  args: {
    dismissible: true,
    dismissLabel: 'Remove',
    onDismiss: fn(),
  },
  render: (args) => <FilterBar {...args} />,
};

Custom Dismiss Icon

Custom icon
export const CustomDismissIcon: Story = {
  args: {
    children: 'Custom icon',
    dismissible: true,
    onDismiss: fn(),
    dismissIcon: (
      <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor">
        <path d="M2 6h8" strokeWidth="1.5" strokeLinecap="round" />
      </svg>
    ),
  },
  render: (args) => <DismissibleTag {...args} />,
};

With Icon

With icon
export const WithIcon: Story = {
  args: {
    icon: <DotIcon />,
    children: 'With icon',
  },
};

Appearances

filledoutlinebrand
export const Appearances: Story = {
  args: {
    dismissible: true,
    onDismiss: fn(),
  },
  render: (args) => (
    <div className="flex flex-wrap items-center gap-2">
      {APPEARANCES.map((appearance) => (
        <Tag key={appearance} {...args} appearance={appearance}>
          {appearance}
        </Tag>
      ))}
    </div>
  ),
};

Sizes

mediumWith iconKatri AthokasDismissible medium
smallWith iconKatri AthokasDismissible small
extra-smallWith iconKatri AthokasDismissible extra-small
export const Sizes: Story = {
  args: {
    onDismiss: fn(),
  },
  // Only the dismissible tag takes `onDismiss` (without `dismissible` it would be ignored).
  render: ({ onDismiss, ...args }) => (
    <div className="flex flex-col items-start gap-3">
      {SIZES.map((size) => (
        <div key={size} className="flex flex-wrap items-center gap-2">
          <Tag {...args} size={size}>
            {size}
          </Tag>
          <Tag {...args} size={size} icon={<DotIcon />}>
            With icon
          </Tag>
          <Tag {...args} size={size} media={<Avatar name="Katri Athokas" decorative />}>
            Katri Athokas
          </Tag>
          <Tag {...args} size={size} dismissible onDismiss={onDismiss}>
            {`Dismissible ${size}`}
          </Tag>
        </div>
      ))}
    </div>
  ),
};

Shapes

circularrounded
export const Shapes: Story = {
  args: {
    dismissible: true,
    onDismiss: fn(),
  },
  render: (args) => (
    <div className="flex flex-wrap items-center gap-2">
      {SHAPES.map((shape) => (
        <Tag key={shape} {...args} shape={shape}>
          {shape}
        </Tag>
      ))}
    </div>
  ),
};

Disabled

DisabledDisabled and dismissible
export const Disabled: Story = {
  args: {
    disabled: true,
    onDismiss: fn(),
  },
  // Only the dismissible tag takes `onDismiss` (without `dismissible` it would be ignored).
  render: ({ onDismiss, ...args }) => (
    <div className="flex flex-wrap items-center gap-2">
      <Tag {...args}>Disabled</Tag>
      <Tag {...args} dismissible onDismiss={onDismiss}>
        Disabled and dismissible
      </Tag>
    </div>
  ),
};

Disabled Focusable

Disabled but focusable
export const DisabledFocusable: Story = {
  args: {
    disabledFocusable: true,
    dismissible: true,
    onDismiss: fn(),
  },
  render: (args) => <Tag {...args}>Disabled but focusable</Tag>,
};

Selected

Selected filledSelected outlineSelected brand
export const Selected: Story = {
  args: {
    selected: true,
    dismissible: true,
    onDismiss: fn(),
  },
  render: (args) => (
    <div className="flex flex-wrap items-center gap-2">
      {APPEARANCES.map((appearance) => (
        <Tag key={appearance} {...args} appearance={appearance}>
          {`Selected ${appearance}`}
        </Tag>
      ))}
    </div>
  ),
};

With Media

Katri AthokasReviewer
export const WithMedia: Story = {
  args: {
    dismissible: true,
    onDismiss: fn(),
  },
  render: (args) => (
    <div className="flex flex-wrap items-center gap-2">
      <Tag {...args} media={<Avatar name="Katri Athokas" decorative />}>
        Katri Athokas
      </Tag>
      <Tag
        {...args}
        media={
          <Avatar
            name="Elvia Atkins"
            badge={<PresenceBadge status="available" size="extra-small" />}
          />
        }
      >
        Reviewer
      </Tag>
    </div>
  ),
};

Secondary Text

Katri AthokasDesigner
export const SecondaryText: Story = {
  args: {
    media: <Avatar name="Katri Athokas" decorative />,
    secondaryText: 'Designer',
    dismissible: true,
    onDismiss: fn(),
    children: 'Katri Athokas',
  },
};
export const AsLink: AnchorStory = {
  args: {
    as: 'a',
    href: '#topics/react',
    children: 'React',
  },
};
React
export const DismissibleLink: Story = {
  args: {
    dismissible: true,
    onDismiss: fn(),
    children: <a href="#topics/react">React</a>,
  },
  render: (args) => <DismissibleTag {...args} />,
};

Props

NameTypeRequiredDefaultDescription
appearance'filled' | 'outline' | 'brand'Nothe TagGroup's `appearance`, else 'filled'

Colour scheme: filled (a neutral fill), outline (a border on the surface behind it) or brand (a light brand tint that follows the brand ramp).

size'small' | 'extra-small' | 'medium'Nothe TagGroup's `size`, else 'medium'

medium (28px tall, the 0.10 look), small (24px) or extra-small (20px); an Avatar in media is 24, 20 or 16px. Fluent's medium tag is 32px.

shape'circular' | 'rounded'Nothe TagGroup's `shape`, else 'circular'

circular (a pill, the 0.10 look) or rounded (4px corners). Fluent's default is rounded.

disabledbooleanNofalse

Dims the tag and disables its Dismiss button natively (no onDismiss, out of the Tab order), whatever dismissIcon passes. A disabled TagGroup disables every tag. A Dismiss button that has focus when the tag is disabled keeps it, unavailable, until focus leaves it. Rendered as data-disabled. With as="a" the link is disabled too: aria-disabled="true", role="link", no href (out of the Tab order) and no click; a link that has focus keeps it, and its href, until focus leaves it. With another as, an element that takes a native disabled (a <button>) or a component receives disabled; a <button> that has focus when it is disabled keeps it, unavailable (aria-disabled, no click), until focus leaves it.

disabledFocusablebooleanNofalse

Like disabled (the dimmed look, data-disabled, no onDismiss, no click) but the tag's controls stay focusable and in the Tab order and a TagGroup's arrow-key order: the Dismiss button renders aria-disabled="true", data-disabled and data-disabled-focusable instead of the native disabled, and its click, Enter, Space, Delete and Backspace do nothing. A link root (as="a") keeps its href and its Tab stop; a button root (as="button") and an element that takes a native disabled or a component get aria-disabled and data-disabled-focusable instead of disabled, and no click reaches onClick. Wins over disabled and over a disabled TagGroup's. Fluent's Tag has no counterpart.

selectedbooleanNofalse

Draws the selected look (the brand fill) and sets data-selected. A Tag is not interactive, so the state is not announced: for a tag the user selects, use InteractionTag (its InteractionTag.Primary is a toggle button). Disabled wins over the selected look.

valuestringNo

Identifies the tag in a TagGroup: the value its onDismiss receives (without one, a generated id). Give every tag of a group its own value. Renders nothing on the default <span>; with as, an element that takes a native value (a <button>, an <li>) still receives it.

mediaSlot<'span'>No

A visual before the text, usually an Avatar, which takes the tag's size (24, 20 or 16px) unless it sets its own size. Not interactive. It is not hidden from assistive technology: pass decorative to an Avatar whose name repeats the tag's text. Use media or icon, not both.

iconSlot<'span'>No

A decorative icon before the text (aria-hidden), in a 20, 16 or 12px box.

secondaryTextReact.ReactNodeNo

A second, smaller line under the text (secondaryText="Designer"). It is not part of the Dismiss button's name. A small or extra-small tag grows to 28px to fit it.

dismissiblebooleanNothe TagGroup's `dismissible`, else `false`

Whether the tag renders a Dismiss button. onDismiss and dismissIcon take effect only with it (a development warning says so when they are passed without it). dismissible={false} opts a tag out of a dismissible TagGroup. A Dismiss button cannot sit inside a link or a button: a dismissible tag rendered as one holds it inside (a development warning). For a dismissible link chip, put the link in the content, <Tag dismissible><a href="/topics/react">React</a></Tag>; for an action with a separate Dismiss button, use InteractionTag. Fluent's dismissible Tag is a single button that dismisses when it is activated.

onDismiss() => voidNo

Called when the Dismiss button is activated: a click, Enter, Space, Delete or Backspace (a held key dismisses once). Passing it does not render the button: set dismissible too. In a TagGroup the group's onDismiss(value) is called after it, and focus moves to the next tag when the tag is removed. A standalone Tag cannot keep focus once you remove it: move focus yourself (see "Focus after dismissal" on Tag). Fluent's Tag dismisses on Delete and Backspace only inside a TagGroup.

dismissIconSlot<'span'>No

Content of the dismiss button (an icon). The Tag always renders its own dismiss <button type="button">, wired to onDismiss and named by dismissLabel plus the tag's text (its children; not media, icon or secondaryText); this slot only replaces the icon inside it.

A <button> element or a Wave Button passed here is not nested (a button cannot contain a button): its props are merged into the dismiss button (its onClick runs first and can call preventDefault() to skip onDismiss) and a development warning recommends icon content. A Wave Button's own props are not attributes: its icon becomes decorative content before its children (after them with iconPosition="after"), disabledFocusable makes the dismiss button unavailable but focusable as on the Button (onDismiss is not called), and appearance and size are ignored. A slot object is the icon element, not the button: its attributes, className, id, ref and event handlers included, go to that element, so handle the dismissal in onDismiss. Its aria-* attributes go to the dismiss button, because the icon is aria-hidden, except the naming attributes (see below). A slot object whose as is a <button> or a Wave Button cannot render inside the button: its children render as the icon (the default icon when it has none) and its props are dropped, with a development warning.

The dismiss button's name is dismissLabel plus the tag's text ("Dismiss Cherry"): aria-label and aria-labelledby on the slot are ignored (development warning). Icon content is decorative (aria-hidden). The children of a merged <button>/Button (or its dangerouslySetInnerHTML markup) are rendered as is inside the dismiss button, next to the decorative icon of a Wave Button: when they render a text label (at least two letters or digits outside aria-hidden/hidden content, text from components such as translations included), that text replaces dismissLabel in the name, so the name contains the visible label (WCAG 2.5.3): <button>Remove</button> or <Button icon={<CloseIcon />}>Remove</Button> on "Cherry" is named "Remove Cherry". An icon or a lone character (x, ×) keeps "Dismiss Cherry". Text hidden only with CSS still counts as the label.

When the slot renders no content ([], <></>, a childless merged button, a slot object without children), the default dismiss icon is shown; a slot object then styles it, e.g. { className: 'text-error' }. A slot object that renders a component or a void element ({ as: CloseIcon }, { as: 'img', src, alt: '' }) or sets dangerouslySetInnerHTML is the icon itself: no default icon is added. Only takes effect with dismissible.

slotProps.dismissButton reaches the same button; its attributes replace those of a merged button (see there).

dismissLabelstringNo'Dismiss'

Visually hidden text that names the dismiss button together with the tag's text (its children; not media, icon or secondaryText; aria-labelledby), e.g. "Dismiss Cherry". Localise it here. A text label rendered by a merged <button> slot replaces it (see dismissIcon). TagPicker names the Dismiss buttons of the tags it renders itself with its labels.remove.

slotProps{ primaryText?: SlotPart<'span'>; secondaryText?: SlotPart<'span'>; dismissButton?: SlotPart<'button'> }No

Props for the elements the tag draws around its text and for its Dismiss button, by part, merged into each part's own (Fluent UI's primaryText and secondaryText slot props): your classes after the part's (yours win a conflict), your styles over its styles, your handlers before its handlers, your ids added to its aria-labelledby and aria-describedby, and your ref beside its ref. Every attribute the tag sets on a part is locked and keeps the tag's value; you add the attributes it does not set. A part takes no children: the tag draws the text, and dismissIcon fills the Dismiss button. media and icon are slots of their own.

The two text parts lock, unset, role, tabIndex, aria-label (it would replace the text in a name), data-roving-container (it would take a link in the text out of a TagGroup's arrow order), the markers by which a TagGroup finds its tags and their Dismiss buttons (data-wave-tag-item, data-wave-tag-dismiss) and hidden, inert and aria-hidden. They carry no handler of the tag: an event on a text part reaches the tag after yours, so preventDefault() in yours skips the tag's handling of it (Delete and Backspace on a link in the text no longer dismiss), while the tag's own on… props still run. A disabled link or button tag activates nothing, and your onClick on its text parts is not called either.

asReact.ElementTypeNo'span'

Render as a different element or component (its props are type-checked).

Any other prop is passed to the element it renders (HTMLSpanElement).

Parts

  • primaryText
  • secondaryText
  • dismissButton

Stable class names

PartClass
rootwave-tag
mediawave-tag__media
iconwave-tag__icon
primaryTextwave-tag__primary-text
secondaryTextwave-tag__secondary-text
dismissButtonwave-tag__dismiss-button
dismissIconwave-tag__dismiss-icon