生态产品多个设计器现已发布候选版本

查看生态总览
Skip to content

Tag ​

Data display component. This page is the API reference, generated from the source code. Usage guidance and live examples are on the Chinese page.

Anatomy ​

Parts in bold are required.

data-scope="tag": root · label · close-trigger

API reference ​

Descriptions of individual props, events and slots are written in Chinese and appear on the Chinese page.

Artifacts ​

LayerValue
Custom element<xh-tag>
Vue componentsXhTagCloseTrigger XhTagLabel XhTagRoot
ComposableuseTag
State machinetagMachine
Skin@xihan-ui/styles/tag.css

Props ​

PropTypeRequired
variantTagVariant
toneTone
sizeSize
closableboolean
disabledboolean
readOnlyboolean
openboolean
defaultOpenboolean
onOpenChange(details: TagOpenChangeDetails) => void
translationsPartial<TagTranslations>

Events ​

Custom elements put the payload in detail; Vue emits an event of the same name.

EventPayload
open-changeTagOpenChangeDetails

State ​

Public state is written to data-state.

PartValues
root'open' | 'closed'

The following names are internal to the state machine.

States: open · closed

Events: OPEN · CLOSE · CONTROLLED.OPEN · CONTROLLED.CLOSED · PRESS.START · PRESS.END · ROOT.RENDERED

Guards: isOpenControlled · canPress

connect API ​

getXxxProps() returns the host attributes of the matching part.

MemberType
openboolean
closableboolean
disabledboolean
setOpen(next: boolean) => void
getRootProps() => T['element']
getLabelProps() => T['element']
getCloseTriggerProps() => T['button']

Accessibility ​

Keyboard ​

Specification: W3C APG. Each row is a stable behavior id that the conformance tests cover; the conditions and effects are described on the Chinese page.

KeysBehavior
Enter / Spacetag.kbd.close
Enter / Spacetag.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
close-triggeraria-labeltranslations.close

Style reference ​

Skin ​

@xihan-ui/styles/tag.css is written against [data-scope="tag"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-tag in place of data-scope (same specificity) and sits in the xihan.components layer. Put overrides in xihan.overrides; the part selectors work as usual.

Data attributes ​

Produced by connect; valueless attributes are omitted while their condition does not hold.

PartAttributeValue
rootdata-disabled'' (present only while the condition holds)
rootdata-pressed'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-state'open' | 'closed'
rootdata-toneprops.tone
rootdata-variantprops.variant
rootdata-xh-ink-surface'' (present only while the condition holds)
close-triggerdata-disabled'' (present only while the condition holds)
close-triggerdata-pressed'' (present only while the condition holds)

CSS variables ​

The public override slots, generated from what the standalone skin actually consumes.

VariablePartCSS propertyStateDefault from
--xh-tag-bgroot--xh-ink-surface
background
default
disabled
is(:not([data-variant])
not([data-disabled])
not([data-tone], [data-disabled])
tone
variant
variant=outline
variant=solid
variant=subtle
where([data-xh-field-chrome][data-variant='subtle']:not(:focus-within)
xh-field-chrome
xh-ink-surface
--xh-_tone
--xh-_tone-subtle
--xh-bg-brand
--xh-bg-subtle
--xh-bg-surface
--xh-tag-bg-disabledroot--xh-ink-surface
background
disabled
tone
variant=solid
xh-ink-surface
--xh-bg-muted
--xh-bg-muted-opaque
--xh-tag-borderrootborder
border-color
default
disabled
is(:not([data-variant])
not([data-disabled])
not([data-tone], [data-disabled])
tone
variant
variant=outline
variant=subtle
where([data-xh-field-chrome][data-variant='subtle']:not(:focus-within)
xh-field-chrome
--xh-_tone-border-control
--xh-border-default
transparent
--xh-tag-border-disabledrootborder-colordisabled
tone
--xh-border-default
--xh-tag-close-bg-activeclose-trigger
root
backgrounddisabled
is(:active, [data-pressed])
is(:not([data-variant])
not(:disabled)
not([data-disabled])
not([data-tone], [data-disabled])
pressed
tone
variant
variant=outline
variant=subtle
where([data-xh-field-chrome][data-variant='subtle']:not(:focus-within)
xh-field-chrome
--xh-bg-subtle-hover
color-mix(in oklab, currentColor 22%, transparent)
--xh-tag-close-bg-hoverclose-trigger
root
backgrounddisabled
hover
is(:not([data-variant])
not(:disabled)
not([data-disabled])
not([data-tone], [data-disabled])
tone
variant
variant=outline
variant=subtle
where([data-xh-field-chrome][data-variant='subtle']:not(:focus-within)
xh-field-chrome
--xh-bg-subtle
color-mix(in oklab, currentColor 14%, transparent)
--xh-tag-close-fgclose-triggercolordefaultcurrentColor
--xh-tag-close-radiusclose-triggerborder-radiusdefault--xh-shape-inset
--xh-tag-close-sizeclose-triggerblock-size
inline-size
inset
default--xh-control-indicator-size
--xh-tag-fgrootcolordefault
is(:not([data-variant])
tone
variant
variant=ghost
variant=outline
variant=solid
variant=subtle
--xh-_tone-fg
--xh-_tone-on
--xh-fg-default
--xh-fg-on-brand
--xh-tag-font-sizerootfont-sizedefault--xh-_tag-font-size
--xh-tag-font-weightrootfont-weightdefault--xh-font-weight-medium
--xh-tag-gaprootgapdefault--xh-_tag-gap
--xh-tag-hrootmin-block-sizedefault--xh-_tag-h
--xh-tag-icon-sizeroot--xh-icon-sizedefault--xh-glyph-size-text
--xh-tag-pxrootpadding-inlinedefault--xh-_tag-px
--xh-tag-pyrootpadding-blockdefault--xh-_tag-py
--xh-tag-radiusrootborder-radiusdefault
where([data-xh-field-chrome])
xh-field-chrome
--xh-shape-control
--xh-shape-inset
--xh-tag-shadowrootbox-shadowdefault
variant=solid
none

Released under The MIT License