Tag
Compact labels for categories, filters, semantic states, and removable metadata.
Tag
Demo
Tags
Loading demo...
Closable
Use closable tags for removable filters or user-defined labels.
Loading demo...
Icon and Custom Color
Loading demo...
Interaction and Disabled
Loading demo...
Tag + Button
Loading demo...
Interaction Contract
- The root is static metadata with no live-region role; tag text must be meaningful without relying on color.
labeldefaults to an empty string;nullis normalized to an empty string.- The default slot replaces
labelcontent but keeps the icon and close affordance. colordefaults tovar(--tx-color-primary). Missingbackgroundandborderare derived fromcolorwithcolor-mix.- The close affordance is a native
button type="button"witharia-label="Remove tag". - Close clicks stop propagation, so
closedoes not also emit the tag-levelclickevent. disabledreduces opacity, disables the close button, and blocks bothclickandcloseemits.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | null | '' | Text content when the default slot is not provided. |
icon | string | '' | Leading icon class. |
color | string | 'var(--tx-color-primary)' | Main text/icon color and base color for derived background/border. |
background | string | '' | Custom background color. Defaults to a translucent mix of color. |
border | string | '' | Custom border color. Defaults to a translucent mix of color. |
size | 'sm' | 'md' | 'sm' | Tag density. |
closable | boolean | false | Render the close button. |
disabled | boolean | false | Disable tag click and close interactions. |
pill | boolean | false | Use a fully rounded pill shape (adds .pill to the root); for filter chips and similar cases that should read differently in shape from square tags. |
variant | 'outline' | 'soft' | 'plain' | 'outline' | Fill recipe; see the table below. |
dot | string | - | Leading dot colour; omit to render no dot. Lets a tag carry a category hue while its text stays legible. |
dotSize | number | 6 | Dot diameter in pixels. |
count | number | - | Trailing count badge; 0 renders, omitting the prop renders nothing. |
The three variant recipes:
| Value | Fill | Hairline | Text | Use |
|---|---|---|---|---|
outline | 12% | 32% | Full-strength hue | The default, byte-identical to existing tags |
soft | 20% | 34% | 92% hue mixed toward ink | Steadier for 11px text on a coloured fill |
plain | Neutral fill | Neutral hairline | Secondary ink | Ignores color; for overflow counters like +3 and metadata that must not compete |
An explicit background / border still overrides whichever variant is chosen.
Events
| Event | Payload | Description |
|---|---|---|
click | MouseEvent | Emitted when the tag root is clicked and disabled=false. |
close | - | Emitted when the close button is clicked and disabled=false. |
Slots
| Slot | Props | Description |
|---|---|---|
default | - | Replaces the label text inside the tag content area. |
Best Practices
- Use tags for metadata and state hints, not as a replacement for primary buttons.
- Keep
labelconcise; long strings break the compact rhythm of tables and filter rows. - Use
closablefor filters, user labels, and temporary scopes where removal is expected. - Provide explicit
background/borderwhen using custom raw colors that need stronger contrast. - For destructive removal, confirm in the host before mutating data;
TxTagonly emits intent.
Review Notes
- Accessibility note: The close affordance is a real
button, but the tag-levelclickhandler lives on a non-focusablespan. Useclickonly for optional pointer affordances; choose a button or checkbox pattern when the tag action must be keyboard reachable. - Verified coverage:
tag.test.tschecks label/icon/style rendering, default-slot override, click and close emission separation, disabled blocking, and disabled close-button state.
Source
- Component source:
packages/tuffex/packages/components/src/tag/src/TxTag.vue. - Types:
packages/tuffex/packages/components/src/tag/src/types.tsexportsTagPropsandTagEmits. - Export alias:
packages/tuffex/packages/components/src/tag/index.tsexportsTag,TxTag,TagProps,TagEmits, andTxTagInstance. - Coverage:
packages/tuffex/packages/components/src/tag/__tests__/tag.test.tsverifies rendering, slots, events, and disabled behavior.
查看源码
packages/tuffex/packages/components/src/tag/index.ts