Tag

A compact label for categories, filters, and states.

VerifiedSince 0.3.4

Usage

Colors and Sizes

color sets the text color and derives the background and border.

Loading demo...

Closable

closable renders a close button; close only signals intent, and the host updates the data.

Loading demo...

Icon and Custom Color

background and border override the colors derived from color.

Loading demo...

Interaction and Disabled

With @click bound, the tag becomes a focusable button; disabled blocks click and close.

Loading demo...

Tag + Button

Loading demo...

Best Practices

  • Use tags for metadata and state hints, not as a replacement for primary buttons.
  • Keep label short and readable without relying on color.
  • Use closable for removable filters, user labels, and temporary scopes.
  • Pass explicit background / border when a raw custom color lacks contrast.
  • Confirm removal in the host; TxTag only emits intent.

API Reference

Props

PropTypeDefaultDescription
labelstring | null''Text shown when there is no default slot; null counts as empty.
iconstring''Leading icon class.
colorstring'var(--tx-color-primary)'Text and icon color; the base for the derived background and border.
backgroundstring''Custom background; defaults to a translucent mix of color.
borderstring''Custom border; defaults to a translucent mix of color.
size'sm' | 'md''sm'Tag density.
closablebooleanfalseRenders the close button.
closeAriaLabelstring'Remove tag'aria-label of the close button; pass localized text.
disabledbooleanfalseDisables click and close.
pillbooleanfalseFully rounded pill shape, for filter chips that must differ from square tags.
variant'outline' | 'soft' | 'plain''outline'Fill recipe; see the table below.
dotstring-Leading dot color; no dot when omitted.
dotSizenumber6Dot diameter in px.
countnumber-Trailing count; 0 renders, omitting it renders nothing.
variantFillHairlineTextUse
outline12%32%Full-strength hueDefault
soft20%34%92% hue mixed toward ink11px text on a colored fill
plainNeutral fillNeutral hairlineSecondary inkIgnores color; for overflow counters like +3 and secondary metadata

An explicit background / border overrides any variant.

Events

EventPayloadDescription
clickMouseEventFires on click unless disabled; with a listener bound, Enter / Space fire it too.
close-Fires when the close button is clicked, unless disabled.

Slots

SlotPropsDescription
default-Replaces the label text, keeping the icon and close button.

Overview

  • Without @click, the root is static metadata with no role; with it, the root is a focusable role="button" that carries aria-disabled when disabled.
  • The close button is a native button type="button" whose aria-label comes from closeAriaLabel.
  • Close clicks stop propagating, so close never also fires click.
  • disabled lowers opacity, disables the close button, and blocks click and close.

Technologies

  • Source: packages/tuffex/packages/components/src/tag/.
查看源码
packages/tuffex/packages/components/src/tag/index.ts