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
export const Default: Story = {};Dismissible
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
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
export const WithIcon: Story = {
args: {
icon: <DotIcon />,
children: 'With icon',
},
};Appearances
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
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
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
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
export const DisabledFocusable: Story = {
args: {
disabledFocusable: true,
dismissible: true,
onDismiss: fn(),
},
render: (args) => <Tag {...args}>Disabled but focusable</Tag>,
};Selected
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
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
export const SecondaryText: Story = {
args: {
media: <Avatar name="Katri Athokas" decorative />,
secondaryText: 'Designer',
dismissible: true,
onDismiss: fn(),
children: 'Katri Athokas',
},
};As Link
export const AsLink: AnchorStory = {
args: {
as: 'a',
href: '#topics/react',
children: 'React',
},
};Dismissible Link
export const DismissibleLink: Story = {
args: {
dismissible: true,
onDismiss: fn(),
children: <a href="#topics/react">React</a>,
},
render: (args) => <DismissibleTag {...args} />,
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
appearance | 'filled' | 'outline' | 'brand' | No | the TagGroup's `appearance`, else 'filled' | Colour scheme: |
size | 'small' | 'extra-small' | 'medium' | No | the TagGroup's `size`, else 'medium' |
|
shape | 'circular' | 'rounded' | No | the TagGroup's `shape`, else 'circular' |
|
disabled | boolean | No | false | Dims the tag and disables its Dismiss button natively (no |
disabledFocusable | boolean | No | false | Like |
selected | boolean | No | false | Draws the selected look (the brand fill) and sets |
value | string | No | Identifies the tag in a TagGroup: the value its | |
media | Slot<'span'> | No | A visual before the text, usually an | |
icon | Slot<'span'> | No | A decorative icon before the text ( | |
secondaryText | React.ReactNode | No | A second, smaller line under the text ( | |
dismissible | boolean | No | the TagGroup's `dismissible`, else `false` | Whether the tag renders a Dismiss button. |
onDismiss | () => void | No | 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 | |
dismissIcon | Slot<'span'> | No | Content of the dismiss button (an icon). The Tag always renders its own dismiss A The dismiss button's name is When the slot renders no content (
| |
dismissLabel | string | No | 'Dismiss' | Visually hidden text that names the dismiss button together with the tag's text (its children; not |
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 The two text parts lock, unset, | |
as | React.ElementType | No | '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
primaryTextsecondaryTextdismissButton
Stable class names
| Part | Class |
|---|---|
root | wave-tag |
media | wave-tag__media |
icon | wave-tag__icon |
primaryText | wave-tag__primary-text |
secondaryText | wave-tag__secondary-text |
dismissButton | wave-tag__dismiss-button |
dismissIcon | wave-tag__dismiss-icon |