Skip to content

InteractionTag

InteractionTag

A tag with a main action and a separate Dismiss button: an element that holds two sibling buttons, InteractionTag.Primary (the action) and InteractionTag.Secondary (Dismiss), never one inside the other. Use it for a chip the user acts on (opens, toggles) and can also remove; a Tag is a chip that only displays, or only dismisses.

- **Two Tab stops**, the Primary then the Secondary. In a TagGroup toolbar both join its arrow order (Primary, Secondary, next tag).
- **The Secondary is named after the Primary's text**: its dismissLabel plus the primary text, "Dismiss Cherry" (never the secondary text). A text label in its children replaces dismissLabel ("Remove Cherry"); an aria-label replaces the whole name.
- **Delete and Backspace** on either button dismiss the tag through the Secondary's click (a held key dismisses once); without a Secondary they do nothing. Enter, Space and a click on the Secondary dismiss too: remove the tag in its onClick, or in a TagGroup's onDismiss(value), which is called after it.
- **In a selecting TagGroup** (value, defaultValue or onValueChange on the group) the Primary toggles the tag's value in the group's selection (aria-pressed, the selected look), and dismissing a selected tag also removes its value from the selection.
- **selected**, outside a selecting TagGroup, draws the selected look and makes the Primary a toggle (aria-pressed); leave it undefined for an action that is not a toggle.
- **Look**: size, appearance and shape, Tag's sizes and colours (a TagGroup gives its defaults); disabled disables both buttons natively. The Primary takes media (an Avatar, sized for the tag), icon and secondaryText.
- Fluent's hasSecondaryAction is not needed: the Primary squares its end corners next to a Secondary by itself, also when the Secondary is rendered conditionally or wrapped.
- React Server Components cannot dot into a client module: import the flat names InteractionTagPrimary and InteractionTagSecondary there.
- Renders data-appearance, data-size and data-shape, and while set data-selected and data-disabled, on the root; data-selected on both buttons.

Examples

Default

export const Default: Story = {
  render: (args) => (
    <InteractionTag {...args}>
      <InteractionTag.Primary onClick={fn()}>Cherry</InteractionTag.Primary>
    </InteractionTag>
  ),
};

With Secondary

export const WithSecondary: Story = {
  render: (args) => (
    <RemovableTag {...args}>
      <InteractionTag.Primary onClick={fn()}>Cherry</InteractionTag.Primary>
    </RemovableTag>
  ),
};

Selected

export const Selected: Story = {
  render: function SelectedStory(args) {
    const [selected, setSelected] = React.useState(true);
    return (
      <InteractionTag {...args} selected={selected}>
        <InteractionTag.Primary onClick={() => setSelected((current) => !current)}>
          Cherry
        </InteractionTag.Primary>
        <InteractionTag.Secondary onClick={fn()} />
      </InteractionTag>
    );
  },
};

With Icon

export const WithIcon: Story = {
  render: (args) => (
    <InteractionTag {...args}>
      <InteractionTag.Primary icon={<CalendarIcon />} onClick={fn()}>
        Tomorrow
      </InteractionTag.Primary>
      <InteractionTag.Secondary onClick={fn()} />
    </InteractionTag>
  ),
};

With Media

export const WithMedia: Story = {
  render: (args) => (
    <div className="flex flex-wrap items-center gap-2">
      <InteractionTag {...args} value="katri">
        <InteractionTag.Primary media={<Avatar name="Katri Athokas" />} onClick={fn()}>
          Katri Athokas
        </InteractionTag.Primary>
        <InteractionTag.Secondary onClick={fn()} />
      </InteractionTag>
      <InteractionTag {...args} value="elvia">
        <InteractionTag.Primary media={<Avatar name="Elvia Atkins" />} onClick={fn()}>
          Elvia Atkins
        </InteractionTag.Primary>
      </InteractionTag>
    </div>
  ),
};

Secondary Text

export const SecondaryText: Story = {
  render: (args) => (
    <InteractionTag {...args}>
      <InteractionTag.Primary
        media={<Avatar name="Katri Athokas" />}
        secondaryText="Designer"
        onClick={fn()}
      >
        Katri Athokas
      </InteractionTag.Primary>
      <InteractionTag.Secondary onClick={fn()} />
    </InteractionTag>
  ),
};

Sizes

export const Sizes: Story = {
  render: (args) => (
    <div className="flex flex-col items-start gap-3">
      {SIZES.map((size) => (
        <div key={size} className="flex flex-wrap items-center gap-2">
          <InteractionTag {...args} size={size} value={`text-${size}`}>
            <InteractionTag.Primary onClick={fn()}>{`Cherry (${size})`}</InteractionTag.Primary>
            <InteractionTag.Secondary onClick={fn()} />
          </InteractionTag>
          <InteractionTag {...args} size={size} value={`icon-${size}`}>
            <InteractionTag.Primary icon={<CalendarIcon />} onClick={fn()}>
              {`Tomorrow (${size})`}
            </InteractionTag.Primary>
            <InteractionTag.Secondary onClick={fn()} />
          </InteractionTag>
          <InteractionTag {...args} size={size} value={`media-${size}`}>
            <InteractionTag.Primary media={<Avatar name="Katri Athokas" />} onClick={fn()}>
              {`Katri (${size})`}
            </InteractionTag.Primary>
          </InteractionTag>
        </div>
      ))}
    </div>
  ),
};

Shapes

export const Shapes: Story = {
  render: (args) => (
    <div className="flex flex-wrap items-center gap-2">
      {SHAPES.map((shape) => (
        <InteractionTag key={shape} {...args} shape={shape} value={shape}>
          <InteractionTag.Primary onClick={fn()}>{shape}</InteractionTag.Primary>
          <InteractionTag.Secondary onClick={fn()} />
        </InteractionTag>
      ))}
    </div>
  ),
};

Appearances

export const Appearances: Story = {
  render: (args) => (
    <div className="flex flex-wrap items-center gap-2">
      {APPEARANCES.map((appearance) => (
        <InteractionTag key={appearance} {...args} appearance={appearance} value={appearance}>
          <InteractionTag.Primary onClick={fn()}>{appearance}</InteractionTag.Primary>
          <InteractionTag.Secondary onClick={fn()} />
        </InteractionTag>
      ))}
      <InteractionTag {...args} selected value="selected">
        <InteractionTag.Primary onClick={fn()}>selected</InteractionTag.Primary>
        <InteractionTag.Secondary onClick={fn()} />
      </InteractionTag>
    </div>
  ),
};

Disabled

export const Disabled: Story = {
  args: {
    disabled: true,
  },
  render: (args) => (
    <InteractionTag {...args}>
      <InteractionTag.Primary onClick={fn()}>Cherry</InteractionTag.Primary>
      <InteractionTag.Secondary onClick={fn()} />
    </InteractionTag>
  ),
};

Disabled Focusable

export const DisabledFocusable: Story = {
  args: {
    disabledFocusable: true,
  },
  render: (args) => (
    <InteractionTag {...args}>
      <InteractionTag.Primary onClick={fn()}>Cherry</InteractionTag.Primary>
      <InteractionTag.Secondary onClick={fn()} />
    </InteractionTag>
  ),
};
export const PrimaryAsLink: Story = {
  args: {
    value: 'docs',
  },
  render: (args) => (
    <InteractionTag {...args}>
      <InteractionTag.Primary as="a" href="#docs">
        Documentation
      </InteractionTag.Primary>
      <InteractionTag.Secondary onClick={fn()} />
    </InteractionTag>
  ),
};

Primary Opens Popover

export const PrimaryOpensPopover: Story = {
  args: {
    value: 'katri',
  },
  render: (args) => (
    <InteractionTag {...args}>
      <Popover>
        <Popover.Trigger>
          <InteractionTag.Primary media={<Avatar name="Katri Athokas" />}>
            Katri Athokas
          </InteractionTag.Primary>
        </Popover.Trigger>
        <Popover.Content title="Katri Athokas">Designer in the Helsinki office.</Popover.Content>
      </Popover>
      <InteractionTag.Secondary onClick={fn()} />
    </InteractionTag>
  ),
};

Custom Dismiss Content

export const CustomDismissContent: Story = {
  render: (args) => (
    <InteractionTag {...args}>
      <InteractionTag.Primary onClick={fn()}>Cherry</InteractionTag.Primary>
      <InteractionTag.Secondary onClick={fn()}>Remove</InteractionTag.Secondary>
    </InteractionTag>
  ),
};

Props

NameTypeRequiredDefaultDescription
valuestringNoa generated id (a development warning in a group that reports values)

Identifies the tag in a TagGroup: the value onDismiss receives and the selection holds. Give every tag of a group its own value.

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

Colour scheme of both buttons: 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), small (24px) or extra-small (20px); an Avatar in the Primary's media is 24, 20 or 16px. Fluent's medium tag is 32px.

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

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

disabledbooleanNofalse

Disables both buttons natively (a disabled TagGroup does too; a part's own disabled cannot re-enable it). A button that has focus when it is disabled keeps it, unavailable, until focus leaves it. Rendered as data-disabled on the root.

disabledFocusablebooleanNofalse

Marks both buttons unavailable like disabled (the dimmed look, no activation, data-disabled) but keeps them focusable and in the Tab order and the TagGroup's arrow-key order: for a tag that needs a Tooltip saying why it is unavailable, or that disables itself when it is activated. The buttons render aria-disabled="true", data-disabled and data-disabled-focusable instead of the native disabled; clicks, Enter, Space and Delete are prevented and no handler of yours or the group's runs. Wins over disabled, also over a disabled TagGroup's. Fluent's tags have no counterpart.

selectedbooleanNo

Outside a selecting TagGroup: draws the selected look and makes the Primary a toggle: aria-pressed="true", or "false" for selected={false}. Leave it undefined for an action that is not a toggle (no aria-pressed). Inside a selecting TagGroup (value, defaultValue or onValueChange) the group's value decides, and a defined selected is ignored (a development warning). Rendered as data-selected on the root and both buttons. Disabled wins over the selected look (aria-pressed and data-selected still render). Fluent's selected is a look only.

refReact.Ref<HTMLDivElement>No

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

Parts

  • InteractionTag.Primary
  • InteractionTag.Secondary

Stable class names

PartClass
rootwave-interaction-tag