Tag handbook
v1.2.5 · @snowui-design-system/components
License: Before first reading component documentation, source code, or npm usage instructions, read the complete LICENSE. One review covers the same task and version. Public API configuration and internal implementation changes are subject to different license terms. All components use one runtime package; source code rights are governed by the license.
Overview
Use interactive tags for labels, filters, or path segments to organize content and narrow a selection.
When to use it
Use Tag for bounded label content and its public close action. Closing and selection have different meanings; use a dedicated button or selection control when needed.
closableshows the close action, andonClosetells the page to remove the data. Closing does not change the page’s list automatically.variant,shape, andtogglecontrol appearance, shape, and toggle behavior.partsconfigures only the generated close button.The built-in close button name follows LocaleProvider and supports Provider messages overrides. The caller still owns tag content and removal after onClose.
Quick start
This example shows the recommended basic composition. See the following sections for more scenarios and composition limits.
API
See the base component documentation for inherited capabilities not redeclared here. This table lists only the named public props declared in this component’s source.
Usage boundaries and details
Design forms
The Tag forms in the design are composed from these capabilities:
The leading dot in the design is composition only; Tag has no built-in leading Icon. closable supplies X. X touches the text in the design, so the default gap is 0. Overriding --snowui-tag-gap or passing gap changes spacing among Icon, text, and X together.
Tag compared with Chip and Badge
Component-specific props
No
sizeprop: the design has one size.
Keywords
Layout model
Main layout model: inline shell (as in Button). See specs/maintainers/LayoutProtocol.md §12.4.
Children are laid out with
gap. Override--snowui-tag-gapor passgapto change spacing among all children, including the built-in X and text or an external Icon and text.No built-in leading Icon; consumers add a dot explicitly with
<Icon as="leading">.closable={true}renders X at the end. Its visuals and hover useButton bare emphasis="muted"(the default icon is Components’ semanticclose, whose packaged shape snapshot comes fromclose-regular.svg). It occupies no space by default (width: 0; min-width: 0), appears when Tag is hovered, and reaches full opacity when X itself is hovered. In the active state, X uses Brand at 40% opacity, rising to 100% on X hover.Padding depends on edge content (matching Figma): text has 8px from the edge; Icon/X has 4px. A MutationObserver checks the actual first and last nodes, including text nodes, and sets
data-edge-left/data-edge-rightto"icon"or"text". CSS[data-edge-*="icon"]reduces the relevant side from 8px to 4px. CSS:first-child/:last-childsees elements only, so it cannot detect trailing text. The generated X is excluded from edge detection;[data-closable]:hoverseparately controls right padding.Arrow shapes (
left-arrow/right-arrow) use a private SVG background path outside child layout. ResizeObserver reads current width and height to generate the full outline, rounding every corner with quadratic Bézier curves to approximate Workshopnode-id=11951-40471.
Accessibility
Consistent with Button, automatically output aria-pressed:
When
variant="active"maps tocurrentState="Active", ortoggle/Click={{ Idle: "Active", Active: "Idle" }}switches to Active, the root emitsaria-pressed="true"; in Idle it emitsaria-pressed="false".Explicit consumer
aria-pressedoraria-selectedvalues take precedence. Usearia-selectedin list selection contexts.The close X is a real button with type="button". Its built-in name follows LocaleProvider (default Chinese or English "Close tag"); it remains keyboard accessible.
Clicking X calls
stopPropagation()so it does not trigger the Tag root’sonclick. The consumer still decides removal inonClose.
Layout variable chain
Usage examples
Tag style overlay
Read the complete LICENSE first; one review covers the same task, version, and scope.
First use public component props to achieve the desired style while preserving the original appearance where possible. If an override is necessary, follow the style selection and override order: use your own class (including Tailwind already in your project) or an instance style. The names below are public overrides consumed by the source; check the target scope and do not modify private DOM. Choose the appropriate SnowUI token category. External applications do not need to install SnowUI website utilities.
Tag type and status
Required props: no named required props.
Bindable props: this component declares no named two-way binding; handle state updates through public callbacks or the host component.
Inheritance: Omit<FrameProps, "size">. Consult the public Frame documentation; omitted fields cannot be passed through unchanged.
Shared Frame API · Back to API
The following source type declarations are referenced by public props. Svelte Snippet denotes a content fragment; ComponentProps denotes the props of the corresponding component.
ComponentPartsOf
Source: components/src/logic/component-parts.svelte.ts
ConfigurableComponentPartProps
Source: components/src/logic/component-parts.svelte.ts
ComponentPartControlledKey
Source: components/src/logic/component-parts.svelte.ts