TagGroup
A set of tags with one keyboard model: by default an APG toolbar (role="toolbar"), or with role="list" a list of tags that only display.
- **Toolbar** (the default): one Tab stop, the last focused control (at first the first enabled one). Left/Right move between the controls when horizontal (mirrored in RTL), Up/Down when orientation="vertical", the other axis does nothing; the arrows wrap, in DOM order across wrapped rows, and Home/End jump to the first and last control, the same rule as Toolbar. Natively disabled controls are skipped. Use it for tags that are actions: dismissible tags, InteractionTags (both of their buttons join the arrow order), link chips. Renders aria-orientation, and aria-disabled while disabled.
- **List** (role="list"): every tag is a list item (role="listitem"), every control keeps its own Tab stop and the group handles no arrow key. A tag rendered as a link or a button takes no list item role: put the link in the tag's content (<Tag><a href>โฆ</a></Tag>), or wrap the tag in an element with role="listitem".
- **Delete and Backspace** on a tag's Dismiss button, on either button of an InteractionTag with an InteractionTag.Secondary, or on a link in a dismissible tag's text, dismiss the tag (a held key dismisses one tag). Enter, Space and a click on the Dismiss button do too.
- **Defaults for its tags**: size, appearance, shape and, for Tags, dismissible (a tag's own value wins; an InteractionTag is dismissible when it has a Secondary), and disabled, which disables every tag (a tag cannot re-enable itself).
- **onDismiss(value)** is called on every dismissal, after the Tag's own onDismiss or the Secondary's onClick (whose preventDefault() keeps the group from being called). Remove the tag from your state: when the tag that had focus goes, focus moves to the next tag, else the previous one, else fallbackFocusRef, so it never falls to the page. Give every tag a value. A dismissal you refuse (the tag stays) moves no focus.
- **Selection**: with value, defaultValue or onValueChange (Fluent's selectedValues, defaultSelectedValues and onTagSelect) the group selects. Each InteractionTag.Primary is then a toggle (aria-pressed): a click, Enter or Space adds its tag's value to the selection or removes it, after the Primary's onClick (whose preventDefault() cancels the toggle); the arrow keys only move. onValueChange receives the values in selection order, and values without a tag are kept. Dismissing a selected InteractionTag calls onDismiss and then onValueChange without its value. Plain Tags are never selected; selection is multiple only (RadioGroup or Toolbar.RadioGroup for a single choice).
- **Single selection**: selectionMode="single" keeps at most one value selected: a Primary selects its tag and deselects the previous one, and pressing the selected one deselects it.
- **Field**: inside a Field the group takes the Field's id and is labelled by its label and described by its hint and validation message (a toolbar is no labelable element, so the label names it through aria-labelledby); required falls back to the Field's. A toolbar has no aria-invalid or aria-required: the Field's validation message is what a screen reader reads.
- **Forms**: a selecting group with name submits one entry per selected value, also from outside its form with form; required blocks the submission of an empty selection and moves focus to the group's Tab stop (native validation only, no aria-required); a form reset restores defaultValue. A disabled group submits nothing, and a group that does not select renders no form input.
- No accessible name by default: name the group with aria-label or aria-labelledby.
- Renders data-orientation, data-size, data-appearance, data-shape and, while disabled, data-disabled.
Examples
Default
export const Default: Story = {
render: (args) => <FilterBar {...args} />,
};With Interaction Tags
export const WithInteractionTags: Story = {
args: {
'aria-label': 'Reviewers',
dismissible: false,
},
render: (args) => <Reviewers {...args} />,
};Selectable
export const Selectable: Story = {
args: {
'aria-label': 'Fruit',
dismissible: false,
defaultValue: ['plum'],
onValueChange: fn(),
},
render: (args) => <SelectableChips {...args} />,
};Selectable Single
export const SelectableSingle: Story = {
args: {
'aria-label': 'Fruit',
dismissible: false,
selectionMode: 'single',
defaultValue: ['plum'],
onValueChange: fn(),
},
render: (args) => <SelectableChips {...args} />,
};In A Field
Pick one.
export const InAField: Story = {
args: {
dismissible: false,
selectionMode: 'single',
defaultValue: ['plum'],
'aria-label': undefined,
},
render: ({ 'aria-label': _label, ...args }) => (
<Field label="Favourite fruit" hint="Pick one.">
<SelectableChips {...args} />
</Field>
),
};Selectable Dismissible
export const SelectableDismissible: Story = {
args: {
'aria-label': 'Fruit',
dismissible: false,
defaultValue: ['cherry', 'fig'],
onValueChange: fn(),
},
render: (args) => <SelectableDismissibleChips {...args} />,
};Sizes
export const Sizes: Story = {
render: (args) => (
<div className="flex flex-col items-start gap-4">
{SIZES.map((size) => (
<TagGroup key={size} {...args} size={size} aria-label={`Filters, ${size}`}>
<Tag value="red">Red</Tag>
<Tag value="filter" icon={<FilterIcon />}>
In stock
</Tag>
<Tag value="katri" media={<Avatar name="Katri Athokas" />}>
Katri
</Tag>
</TagGroup>
))}
</div>
),
};Appearances
export const Appearances: Story = {
render: (args) => (
<div className="flex flex-col items-start gap-4">
{APPEARANCES.map((appearance) => (
<TagGroup
key={appearance}
{...args}
appearance={appearance}
aria-label={`Filters, ${appearance}`}
>
<Tag value="red">Red</Tag>
<Tag value="blue">Blue</Tag>
<Tag value="large" shape="rounded">
Large (rounded)
</Tag>
</TagGroup>
))}
</div>
),
};Disabled
export const Disabled: Story = {
args: {
disabled: true,
},
render: (args) => (
<TagGroup {...args}>
<Tag value="red">Red</Tag>
<Tag value="blue" disabled={false}>
Blue
</Tag>
<Tag value="large">Large</Tag>
</TagGroup>
),
};Vertical
export const Vertical: Story = {
args: {
orientation: 'vertical',
},
render: (args) => <FilterBar {...args} />,
};Static List
export const StaticList: Story = {
args: {
role: 'list',
'aria-label': 'Skills',
dismissible: false,
},
render: (args) => (
<TagGroup {...args}>
<Tag appearance="brand">TypeScript</Tag>
<Tag>React</Tag>
<Tag>
<a href="#accessibility">Accessibility</a>
</Tag>
</TagGroup>
),
};In A Form
export const InAForm: Story = {
args: {
'aria-label': 'Fruit',
dismissible: false,
name: 'fruit',
required: true,
defaultValue: ['plum'],
onValueChange: fn(),
},
render: (args) => <FruitOrder {...args} />,
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
role | React.AriaRole | No | 'toolbar' |
|
orientation | 'horizontal' | 'vertical' | No | 'horizontal' | Layout and arrow-key axis, as on Toolbar: Left/Right (mirrored in RTL) when horizontal, Up/Down when vertical; a wrapping set moves in DOM order. |
size | 'small' | 'extra-small' | 'medium' | No | 'medium' | Default |
appearance | 'filled' | 'outline' | 'brand' | No | 'filled' | Default |
shape | 'circular' | 'rounded' | No | 'circular' | Default |
disabled | boolean | No | false | Disables every tag: a tag cannot re-enable itself. A control that has focus keeps it, unavailable, until focus leaves it. |
dismissible | boolean | No | false | Default |
selectionMode | 'single' | 'multiple' | No | 'multiple' | How many InteractionTags a selecting group ( |
onDismiss | (value: string) => void | No | Called with the tag's | |
fallbackFocusRef | React.RefObject<HTMLElement | null> | No | Where focus goes when the tag that had it is removed and no other tag can take it, for example an "Add" or "Reset filters" button outside the group. WaveUI-only. | |
value | readonly string[] | No | The selected values (controlled), in selection order: the | |
defaultValue | readonly string[] | No | [] | Initially selected values (uncontrolled; Fluent's |
onValueChange | (value: string[]) => void | No | Called with the new selected values when they change (Fluent's | |
name | string | No | Form field name: one hidden input per selected value (a selecting group only). Fluent's TagGroup submits nothing. | |
form | string | No | The id of the form the hidden inputs belong to, when the group is outside it. | |
required | boolean | No | false | An empty selection blocks the form's submission (native validation only: a toolbar has no |
ref | React.Ref<HTMLDivElement> | No |
Any other prop is passed to the element it renders (HTMLDivElement).
Stable class names
| Part | Class |
|---|---|
root | wave-tag-group |