Skip to content

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.

9:41Tag types
DefaultPrimarySuccess
WarningDangerInfo

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

typescript
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).

9:41Outline and rounding
OutlinedOutlinedOutlined
RoundedRounded outline

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.

9:41Sizes and close
SML
Closable✕Rounded closable✕

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

API ​

Props ​

PropDescriptionTypeDefault
textTag label (the spec's default slot)string''
typeSemantic type, determines background / text / border colorsLhTagTypeDefault
sizeTag size, maps to the size tokensLhTagSizeMedium
plainWhether outlined (semantic light background + semantic text + semantic border)booleanfalse
roundWhether rounded (radius = half the height)booleanfalse
closableWhether to show the close glyph; tapping it fires onClosebooleanfalse
onCloseFired when the close glyph is tapped() => voidEmpty function

LhTagType ​

ValueSolid backgroundSolid textplain background / text / border
Defaultcolor.background.defaultcolor.text.primary— (default is already neutral)
Primarycolor.primary.defaultcolor.onPrimarycolor.primary.bg / .default / .default
Successcolor.success.defaultcolor.onPrimarycolor.success.bg / .default / .default
Warningcolor.warning.defaultcolor.onPrimarycolor.warning.bg / .default / .default
Dangercolor.danger.defaultcolor.onPrimarycolor.danger.bg / .default / .default
Infocolor.info.defaultcolor.onPrimarycolor.info.bg / .default / .default

The default type's border uses color.border.base; semantic types have a transparent border in the solid state.

LhTagSize ​

ValueheightpaddingHorizontalfontSize
Smalltag.height.small (20vp)tag.paddingHorizontal.small (8vp)tag.fontSize.small (12)
Mediumtag.height.medium (24vp)tag.paddingHorizontal.medium (12vp)tag.fontSize.medium (13)
Largetag.height.large (28vp)tag.paddingHorizontal.large (16vp)tag.fontSize.large (14)

Token reference ​

TokenPurpose
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.borderWidthBase corner radius and border width
color.background.default / color.text.primary / color.border.baseThree default-type colors
color.<sem>.default / color.onPrimarySemantic solid background / text
color.<sem>.bgplain-state light background
spacing.xsGap 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 idAssertionLocal test
default-type-renders-textDefault type uses a neutral background/textdefault_type_uses_neutral_tokens
primary-type-uses-primary-tokensPrimary type consumes primary tokensprimary_type_uses_primary_tokens
plain-uses-bg-tokensOutlined state consumes the semantic light-background tokensplain_uses_bg_tokens
small-size-uses-small-tokensSmall consumes the small size tokenssmall_size_uses_small_tokens
round-makes-radius-half-heightRounded state takes half the height as radiusround_makes_radius_half_height
closable-tap-emits-oncloseTapping the close glyph fires onCloseclosable_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.

lh-ui native bloodline · HarmonyOS (ArkTS + ArkUI)