Show · Tag
Tag
Tag component is used to display a collection of concise information for rapid identification and grouping.
Demos
How to import
Basic usage
To use this tag, just wrap the content with the
It can be turned into a closable label by adding the
At this time, clicking x to close will trigger the onClose event, and blocking the default event in onClose can make it still show and not hide after clicking
<Tag>
tag.It can be turned into a closable label by adding the
closable
property.At this time, clicking x to close will trigger the onClose event, and blocking the default event in onClose can make it still show and not hide after clicking
Size
Supports two sizes:
large
and small
(default).Shape
Supports two Shape:
square
(default)、circle
。Color
Tag supports 16 colors including whites from Semi's palette:
amber
, blue
, cyan
, green
, grey
, indigo
, light-blue
, light-green
, lime
, orange
, pink
, purple
, red
, teal
, violet
, yellow
, white
. You can also customize color through style
.Type
Tag supports three different types, including:
light
(default), ghost
, solid
.Avatar Tag
You can get a avatar tag with
avatarSrc
property. avatarShape
can change the shape of avatar tag including square
(default) and circle
.Invisible
You can use
visible
property to control whether the tag is visible.TagGroup
You can pass in configs for tags through
Set the
tagList
to create a TagGroup. The maxTagCount
can be used to cap the number of list and will be displayed as +N
when the limit is exceeded.Set the
showPopover
property to control whether the remaining content is displayed by Popover when hover to + N TagIf the tags in the TagGroup can be deleted, the user needs to process the
tagList
passed to the TagGroup in onTagClose
API Reference
Tag
Properties | Instructions | type | Default | Version |
---|---|---|---|---|
avatarShape | Shape of avatar tag, one of square and circle | string | square | 1.6.0 |
avatarSrc | Source address of avatar tag | string | - | 1.6.0 |
className | Class name | string | ||
closable | Toggle whether the tag can be closed | boolean | false | |
color | Color of tags, one of amber 、 blue 、 cyan 、 green 、 grey 、 indigo 、 light-blue 、 light-green 、 lime 、 orange 、 pink 、 purple 、 red 、 teal 、 violet 、 yellow 、 white | string | grey | |
prefixIcon | prefix icon | ReactNode | 2.44.0 | |
suffixIcon | suffix icon | ReactNode | 2.44.0 | |
shape | Shape of tag, one of square 、 circle | string | square | 2.20.0 |
size | Size, one of small , large | string | small | |
style | Inline style | object | ||
type | Style type, one of ghost , solid , light | string | light | |
visible | Toggle the visibility of the tag | boolean | true | |
tagKey | The key required by React, as the unique identifier of each tag, does not allow repetition | string | number | |
onClick | Callback function when clicking the tag | (e: MouseEvent) => void | - | |
onClose | Callback function when the tag is closed | (tagChildren: ReactNode, e: MouseEvent, tagKey: string | number ) => void | - | e is available in v1.18, tagKey is available in v2.18.0 |
TagGroup
Properties | Instructions | type | Default | Version |
---|---|---|---|---|
avatarShape | Shape of avatar tag, one of square and circle | string | square | 1.6.0 |
className | Class name | string | ||
maxTagCount | Cap number to display, shown as + N when exceeded | number | ||
popoverProps | Popover configuration properties, you can control the popup props like direction , zIndex , trigger , refer to Popover | PopoverProps | {} | |
showPopover | When hover to + N, whether to display the remaining content through Popover | boolean | false | |
size | Size, one of small , large | string | small | |
style | Inline style | CSSProperties | ||
tagList | Label Group data | (TagProps)[] | ||
onTagClose | The callback function when deleting the Tag in the TagGroup | (tagChildren: ReactNode, e: MouseEvent, tagKey: string | number ) => void | - | 2.18.0 |
Accessibility
ARIA
aria-label
is used to indicate the role ofTag
, for deleteable or clickableTag
, we recommend using this attribute
Keyboard and Focus
- If the current
Tag
is interactive, then thisTag
can be focused. Such as:- When the
onClick
attribute is used, the keyboard user can activate thisTag
with theEnter
keys - When the
closable
property istrue
, keyboard users can delete thisTag
by pressing theDelete
key - When a
Tag
is focused, keyboard users can use theEsc
key to defocus the currently focusedTag
- When the
Content Guidelines
- Due to limited space, label text should be as short as possible
- avoid line breaks
- use sentence case