Tag
Used for marking and selection.
Basic Usage
Use the type property to define the tag's type.
Theme Effects
The Tag component provides three theme effects: dark, light (default), and plain.
Closable Tags
Use the closable property to define a closable tag. Clicking the close button triggers the close event.
Dynamic Editing
Dynamic editing can be implemented by responding to the close event triggered when a tag's close button is clicked.
Checkable Tags
Use the checkable property to define a tag that can be selected, paired with v-model:checked.
Selection Status: [ true, false, false ]
Different Sizes
Use the size property to control the tag's dimensions.
Round Tags
Use the round property to make the tag circular/round.
Custom Colors
Use the color property to customize the tag's background color.
Icon Configuration
Use the icon property or #icon slot for the left icon, and the suffix-icon property or #suffixIcon slot for the right icon.
Usage in Nuxt
The Tag component fully supports SSR in Nuxt 3/4. Its lightweight design makes it ideal for status display and categorization in Nuxt projects.
SSR Considerations:
- ✅ All types, sizes, and effects generate HTML offline on the server.
- ✅ Custom colors and rounded corners are supported in SSR.
- ✅ Icon slots (prefix and suffix) are correctly filled on the server.
- 💡 Interactions (like closing or editing) become active after client-side hydration.
Ultra Lightweight
The CSS for the Tag component is highly optimized/atomic, adding minimal style overhead to SSR pages, making it an ideal choice for performance-focused Nuxt apps.
API
Props
| Name | Description | Type | Default |
|---|---|---|---|
| type | Tag type | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'primary' |
| size | Tag size | 'large' | 'default' | 'small' | 'default' |
| effect | Theme effect | 'dark' | 'light' | 'plain' | 'light' |
| closable | Whether the tag is closable | boolean | false |
| round | Whether the tag has rounded corners | boolean | false |
| color | Custom background color | string | — |
| hit | Whether the tag has a border stroke | boolean | false |
| disable-transitions | Whether to disable fade animations | boolean | false |
| checkable | Whether the tag is selectable | boolean | false |
| checked / v-model:checked | Whether the tag is currently selected | boolean | false |
| editable | Whether the tag is editable (double-click to edit) | boolean | false |
| icon | Left icon component | Component | — |
| suffix-icon | Right icon component | Component | — |
Events
| Name | Description | Parameters |
|---|---|---|
| click | Triggers when the tag is clicked | (event: MouseEvent) => void |
| close | Triggers when the close button is clicked | (event: MouseEvent) => void |
| update:checked | Triggers when selection status changes | (checked: boolean) => void |
| change | Triggers when selection status changes | (checked: boolean) => void |
| edit | Triggers when editing is completed | (value: string) => void |
Slots
| Name | Description |
|---|---|
| default | Tag content |
| icon | Custom left icon |
| suffix-icon | Custom right icon |
| close-icon | Custom close icon |
Theme Variables
| Variable | Description | Default |
|---|---|---|
--yh-tag-font-size | Font size | var(--yh-font-size-xs) |
--yh-tag-border-radius | Border radius | var(--yh-radius-sm) |
--yh-tag-bg-color | Background color | (varies by type) |
--yh-tag-border-color | Border color | (varies by type) |
--yh-tag-text-color | Text color | (varies by type) |