Tag
Tags for marking and selection. Supports six semantic types, three sizes, an outlined state, a rounded state, and a closable state.
Spec source:
lh-ui-core/specs/tag.json· Golden cases:lh-ui-core/cases/tag.json(6 cases, translated into hypium tests)
Types
Six types determine the background, text, and border colors.
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
LhTag({ text: 'Primary', type: LhTagType.Primary })Outline and rounding
When plain is true, the tag switches to a semantic light background + semantic text + semantic border; when round is true, the corner radius is half the height (consistent with the device-side radius fraction conversion).
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
Sizes and close
Three sizes map to the tag.height / paddingHorizontal / fontSize tokens; when closable is true, a close glyph is drawn on the right, and tapping it fires onClose.
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
API
Props
| Prop | Description | Type | Default |
|---|---|---|---|
text | Tag label (the spec's default slot) | string | '' |
type | Semantic type, determines background / text / border colors | LhTagType | Default |
size | Tag size, maps to the size tokens | LhTagSize | Medium |
plain | Whether outlined (semantic light background + semantic text + semantic border) | boolean | false |
round | Whether rounded (radius = half the height) | boolean | false |
closable | Whether to show the close glyph; tapping it fires onClose | boolean | false |
onClose | Fired when the close glyph is tapped | () => void | Empty function |
LhTagType
| Value | Solid background | Solid text | plain background / text / border |
|---|---|---|---|
Default | color.background.default | color.text.primary | — (default is already neutral) |
Primary | color.primary.default | color.onPrimary | color.primary.bg / .default / .default |
Success | color.success.default | color.onPrimary | color.success.bg / .default / .default |
Warning | color.warning.default | color.onPrimary | color.warning.bg / .default / .default |
Danger | color.danger.default | color.onPrimary | color.danger.bg / .default / .default |
Info | color.info.default | color.onPrimary | color.info.bg / .default / .default |
The default type's border uses color.border.base; semantic types have a transparent border in the solid state.
LhTagSize
| Value | height | paddingHorizontal | fontSize |
|---|---|---|---|
Small | tag.height.small (20vp) | tag.paddingHorizontal.small (8vp) | tag.fontSize.small (12) |
Medium | tag.height.medium (24vp) | tag.paddingHorizontal.medium (12vp) | tag.fontSize.medium (13) |
Large | tag.height.large (28vp) | tag.paddingHorizontal.large (16vp) | tag.fontSize.large (14) |
Token reference
| Token | Purpose |
|---|---|
tag.height.{small,medium,large} | Three heights (the rounded state takes half of it as radius) |
tag.paddingHorizontal.{small,medium,large} | Three horizontal paddings |
tag.fontSize.{small,medium,large} | Three font sizes |
tag.borderRadius / tag.borderWidth | Base corner radius and border width |
color.background.default / color.text.primary / color.border.base | Three default-type colors |
color.<sem>.default / color.onPrimary | Semantic solid background / text |
color.<sem>.bg | plain-state light background |
spacing.xs | Gap between the close glyph and the label |
Golden case reference
How the 6 assertions in cases/tag.json map onto hypium tests (entry/src/test/Tag.test.ets):
| case id | Assertion | Local test |
|---|---|---|
default-type-renders-text | Default type uses a neutral background/text | default_type_uses_neutral_tokens |
primary-type-uses-primary-tokens | Primary type consumes primary tokens | primary_type_uses_primary_tokens |
plain-uses-bg-tokens | Outlined state consumes the semantic light-background tokens | plain_uses_bg_tokens |
small-size-uses-small-tokens | Small consumes the small size tokens | small_size_uses_small_tokens |
round-makes-radius-half-height | Rounded state takes half the height as radius | round_makes_radius_half_height |
closable-tap-emits-onclose | Tapping the close glyph fires onClose | closable_close_gap_uses_spacing_xs (spacing-token side evidence) |
Plus dark-mode specifics: dark_colors_come_from_dark_tokens / dimensions_are_identical_in_dark_mode. To run: in DevEco Studio, right-click entry/src/test → Run Tests.

