Tagv1.1.2Documentation Under Review
A compact label component for categorization, status indication, and content organization with product-specific sizing and custom styling support.
The Tag component provides a compact, visually distinct label for categorizing content, displaying status, or organizing information. The product variant features smaller sizing optimized for dense layouts and supports custom styling with CVA for branded applications.
Installation
npm install @pmi/catalyst-tagUsage
import { TagRoot, TagSlot, TagButton } from '@pmi/catalyst-tag';
import { TokenIcon, CloseIcon } from '@pmi/catalyst-icons';<TagRoot>
<TagSlot>
<TokenIcon />
</TagSlot>
Tag Text
</TagRoot>Composition Pattern
The Tag component uses a composite pattern with three parts:
- TagRoot: Container that manages tag state and appearance
- TagSlot: Flexible slot for icons or custom content
- TagButton: Optional close/remove button
This pattern allows maximum flexibility while maintaining consistent styling.
Examples
Basic Tag
A simple tag with an icon and text.
Sizes
Tags are available in three sizes optimized for product UIs: small, medium, and large.
Danger State
Use the danger state to indicate warnings, errors, or destructive actions.
Disabled State
Disabled tags have reduced opacity and are not interactive.
With Remove Button
Add a close button for removable tags.
AsChild Pattern
Use the asChild prop to compose tags with other components like buttons.
Interactive States
Tags support hover and focus states for interactive elements.
Custom Styling
Apply custom brand colors and styling using CVA for product-specific designs.
TagRoot
The root container component that manages tag state and appearance.
Prop
Type
TagSlot
A flexible slot for icons or custom content.
Prop
Type
TagButton
An optional button for close/remove functionality.
Prop
Type
Size Reference
Product variant uses smaller sizes optimized for dense UI layouts:
| Size | Height | Text Size | Button Size | Use Case |
|---|---|---|---|---|
| sm | 20px (h-5) | 12px (text-xs) | 14px (size-3.5) | Very compact, data-dense tables |
| md | 24px (h-6) | 14px (text-sm) | 16px (size-4) | Default, balanced appearance |
| lg | 28px (h-7) | 16px (text-base) | 16px (size-4) | Prominent labels, emphasis |
Accessibility
The Tag component follows accessibility best practices:
- Keyboard Navigation: Tags are focusable and navigable with Tab key
- Focus Management:
tabIndexautomatically managed (set to -1 when disabled) - Focus Indicators: Visible outline on focus (2px with offset)
- Button Accessibility: TagButton has proper focus ring and keyboard support
- ARIA Attributes: Semantic HTML structure for screen readers
- Disabled State:
tabIndex={-1}prevents focus on disabled tags
Best Practices
- Focus Management: Set
tabIndex={-1}on TagRoot when using TagButton to prevent double focus. TagButton will receive focus naturally as a button element - Icon Size: Match icon size to tag size (use sm icons for all product tag sizes)
- Remove Functionality: Provide clear visual feedback when tags are removable
- Danger State: Use sparingly for warnings, errors, or destructive actions
- Group Related Tags: Use consistent sizing and spacing in tag collections
- Custom Styling: When using CVA customization, maintain sufficient contrast ratios
- Dense Layouts: Product sizing is optimized for data-heavy interfaces
- Text Length: Keep tag text concise (1-3 words optimal)
- Interactive Elements: TagButton automatically receives focus when TagRoot has tabIndex=-1
Related Components
Table
A semantic HTML table component for product interfaces with customizable styling via CVA. Supports headers, body, footer, captions, styled cells, and brand theming capabilities.
Alert
Display contextual dismissible feedback messages with semantic variants for informational, success, warning, and error states.