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>
),
};Primary As Link
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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
value | string | No | a generated id (a development warning in a group that reports values) | Identifies the tag in a TagGroup: the value |
appearance | 'filled' | 'outline' | 'brand' | No | the TagGroup's `appearance`, else 'filled' | Colour scheme of both buttons: |
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 | Disables both buttons natively (a disabled TagGroup does too; a part's own |
disabledFocusable | boolean | No | false | Marks both buttons unavailable like |
selected | boolean | No | Outside a selecting TagGroup: draws the selected look and makes the Primary a toggle: | |
ref | React.Ref<HTMLDivElement> | No |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
InteractionTag.PrimaryInteractionTag.Secondary
Stable class names
| Part | Class |
|---|---|
root | wave-interaction-tag |