Skip to content

TagGroup

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

Selected: plum
export const Selectable: Story = {
  args: {
    'aria-label': 'Fruit',
    dismissible: false,
    defaultValue: ['plum'],
    onValueChange: fn(),
  },
  render: (args) => <SelectableChips {...args} />,
};

Selectable Single

Selected: plum
export const SelectableSingle: Story = {
  args: {
    'aria-label': 'Fruit',
    dismissible: false,
    selectionMode: 'single',
    defaultValue: ['plum'],
    onValueChange: fn(),
  },
  render: (args) => <SelectableChips {...args} />,
};

In A Field

Selected: plum

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

Selected: cherry, fig
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

TypeScriptReactAccessibility
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

Nothing submitted yet
export const InAForm: Story = {
  args: {
    'aria-label': 'Fruit',
    dismissible: false,
    name: 'fruit',
    required: true,
    defaultValue: ['plum'],
    onValueChange: fn(),
  },
  render: (args) => <FruitOrder {...args} />,
};

Props

NameTypeRequiredDefaultDescription
roleReact.AriaRoleNo'toolbar'

'toolbar': one Tab stop and arrow keys, for tags that are actions (dismissible tags, InteractionTags, links). 'list': a list (every tag gets role="listitem"), each control its own Tab stop and no arrow keys, for tags that only display. Another role keeps the toolbar keyboard; 'listbox' is not supported (an option cannot hold a Dismiss button). Name the group with aria-label or aria-labelledby.

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. aria-orientation (toolbar role) and data-orientation.

size'small' | 'extra-small' | 'medium'No'medium'

Default size of its tags (a tag's own wins) and the gap between them.

appearance'filled' | 'outline' | 'brand'No'filled'

Default appearance of its tags (a tag's own wins).

shape'circular' | 'rounded'No'circular'

Default shape of its tags (a tag's own wins).

disabledbooleanNofalse

Disables every tag: a tag cannot re-enable itself. A control that has focus keeps it, unavailable, until focus leaves it. aria-disabled (not with role="list"), data-disabled.

dismissiblebooleanNofalse

Default dismissible of its Tags (a Tag's own value wins). An InteractionTag is dismissible when it has an InteractionTag.Secondary.

selectionMode'single' | 'multiple'No'multiple'

How many InteractionTags a selecting group (value, defaultValue or onValueChange) keeps selected: 'multiple', each Primary toggles its own value, or 'single', a Primary selects its value and replaces the selected one (pressing the selected tag again deselects it, as a List's single selection). onValueChange then receives an array of at most one value. Naming follows List's selectionMode; Fluent's TagGroup has no single selection. A value with several values in 'single' mode warns in development and shows them all as selected.

onDismiss(value: string) => voidNo

Called with the tag's value on every dismissal: a click, Enter or Space on a Dismiss button, or Delete or Backspace on a tag (Fluent's onDismiss(event, { value })). Remove the tag from your state; when it goes, focus moves to the next tag, else the previous one, else fallbackFocusRef. Fluent's TagGroup moves focus as it calls onDismiss, whether or not the tag goes, and has no fallback. Dismissing a selected tag also removes its value from the selection; Fluent's TagGroup leaves the selection alone.

fallbackFocusRefReact.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.

valuereadonly string[]No

The selected values (controlled), in selection order: the values of the pressed InteractionTags. Passing value, defaultValue or onValueChange makes the group select (Fluent's selectedValues). Plain Tags are never selected.

defaultValuereadonly string[]No[]

Initially selected values (uncontrolled; Fluent's defaultSelectedValues).

onValueChange(value: string[]) => voidNo

Called with the new selected values when they change (Fluent's onTagSelect).

namestringNo

Form field name: one hidden input per selected value (a selecting group only). Fluent's TagGroup submits nothing.

formstringNo

The id of the form the hidden inputs belong to, when the group is outside it.

requiredbooleanNofalse

An empty selection blocks the form's submission (native validation only: a toolbar has no aria-required).

refReact.Ref<HTMLDivElement>No

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

Stable class names

PartClass
rootwave-tag-group