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

查看生态总览
Skip to content

TagsInput ​

Data entry 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="tags-input": root · label · control · input · item · item-input · clear-trigger · count · hidden-input

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-tags-input>
Vue componentsXhTagsInputClearTrigger XhTagsInputControl XhTagsInputCount XhTagsInputHiddenInput XhTagsInputInput XhTagsInputItem XhTagsInputItemDeleteTrigger XhTagsInputItemInput XhTagsInputItemPreview XhTagsInputItemText XhTagsInputLabel XhTagsInputRoot
ComposableuseTagsInput
State machinetagsInputMachine
Skin@xihan-ui/styles/tags-input.css

Props ​

PropTypeRequired
labelledboolean
ariaLabelstring
valuestring[]
defaultValuestring[]
inputValuestring
defaultInputValuestring
maxnumber
allowOverflowboolean
disabledboolean
readOnlyboolean
requiredboolean
invalidboolean
showCountboolean
namestring
placeholderstring
delimiterstring | string[]
validate(tag: string, context: TagsInputValidateContext) => string | string[] | null | undefined
addOnPasteboolean
editableboolean
blurBehaviorTagsInputBlurBehavior | null
variantControlVariant
toneTone
sizeSize
translationsPartial<TagsInputTranslations>
onValueChange(details: TagsInputValueChangeDetails) => void
onClear() => void
onInputValueChange(details: TagsInputInputValueChangeDetails) => void
onTagReject(details: TagsInputTagRejectDetails) => void

Events ​

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

EventPayload
value-changeTagsInputValueChangeDetails
clear``
input-value-changeTagsInputInputValueChangeDetails
tag-rejectTagsInputTagRejectDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhTagsInputCountdefaultTagsInputCountSlotProps
XhTagsInputRootdefaultTagsInputRootSlotProps
XhTagsInputRootlabel—
XhTagsInputRootitem{ value: string }

React adapter props ​

Only the props each component declares itself: DOM attributes inherited from ComponentPropsWithRef are left out, and root props already listed in the Props table are not repeated. The Vue counterpart is the slot table above.

React componentPropTypeRequired
XhTagsInputCountchildrenSlotChildren<TagsInputCountSlotProps>
XhTagsInputItemvaluestringYes
XhTagsInputRootlabelReactNode
XhTagsInputRootrenderItem(value: string) => ReactNode
XhTagsInputRootchildrenSlotChildren<TagsInputRootSlotProps>

State ​

The following names are internal to the state machine.

States: idle · navigating · editing

Events: VALUE.SET · TAG.ADD · VALUE.CLEAR · INPUT.CHANGE · INPUT.COMMIT · INPUT.BLUR · TAG.HIGHLIGHT · TAG.DELETE · TAG.EDIT · EDIT.CHANGE · EDIT.SUBMIT · EDIT.CANCEL · ITEM.FOCUS_LOST · FORM.RESET · PRESS.START · PRESS.END · LIST.TRACKED

Guards: canEdit · canEditTag · canDeleteWithPrev · hasHighlightTarget · canPress · isEditRejected · isBlurEditRejected

connect API ​

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

MemberType
valuestring[]
countnumber
inputValuestring
emptyboolean
disabledboolean
readOnlyboolean
requiredboolean
invalidboolean
maxnumber | undefined
showCountboolean
atMaxboolean
overflowboolean
highlightedValuestring | null
editedValuestring | null
canClearboolean
setValue(next: string[]) => void
addValue(next: string) => void
deleteValue(value: string) => void
clear() => void
setInputValue(next: string) => void
highlight(value: string | null) => void
edit(value: string) => void
getRootProps() => T['element']
getLabelProps() => T['label']
getControlProps() => T['element']
getInputProps() => T['input']
getItemProps(item: TagsInputItemProps) => T['element']
getItemPreviewProps(item: TagsInputItemProps) => T['element']
getItemTextProps(item: TagsInputItemProps) => T['element']
getItemDeleteTriggerProps(item: TagsInputItemProps) => T['button']
getItemInputProps(item: TagsInputItemProps) => T['input']
getClearTriggerProps() => T['button']
getCountProps() => T['element']
getHiddenInputProps() => T['input']

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
Entertags-input.kbd.commit
delimiter (default ,; may be a set)tags-input.kbd.delimiter
Backspacetags-input.kbd.backspace-highlight
Backspacetags-input.kbd.backspace-delete
Deletetags-input.kbd.delete
ArrowLefttags-input.kbd.prev
ArrowRighttags-input.kbd.next
Hometags-input.kbd.first
Endtags-input.kbd.last
Escapetags-input.kbd.escape-navigating
Entertags-input.kbd.edit
Entertags-input.kbd.edit-submit
Escapetags-input.kbd.edit-cancel
Enter / Spacetags-input.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
controlaria-disabled'true' | 'false'
controlaria-labelprops.ariaLabel
controlaria-labelledbyid of the label part | undefined
controlrole'group'
inputaria-invalid'true' | 'false'
inputaria-labelprops.ariaLabel
inputaria-labelledbyid of the label part | undefined
inputaria-required'true' | 'false'
item-inputaria-labellabel.editTagInput(item.value)
clear-triggeraria-labellabel.clearTrigger
countaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/tags-input.css is written against [data-scope="tags-input"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-tags-input 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-at-max'' (present only while the condition holds)
rootdata-disabled'' (present only while the condition holds)
rootdata-empty'' (present only while the condition holds)
rootdata-invalid'' (present only while the condition holds)
rootdata-overflowing'' (present only while the condition holds)
rootdata-readonly'' (present only while the condition holds)
rootdata-required'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-toneprops.tone
rootdata-variantprops.variant
labeldata-disabled'' (present only while the condition holds)
controldata-at-max'' (present only while the condition holds)
controldata-disabled'' (present only while the condition holds)
controldata-empty'' (present only while the condition holds)
controldata-instant'' (present only while the condition holds)
controldata-invalid'' (present only while the condition holds)
controldata-overflowing'' (present only while the condition holds)
controldata-readonly'' (present only while the condition holds)
controldata-variantprops.variant
controldata-xh-action-owner''
controldata-xh-field-chrome''
controldata-xh-field-layout'multi-tag'
controldata-xh-field-sizeprops.size
inputdata-disabled'' (present only while the condition holds)
inputdata-invalid'' (present only while the condition holds)
inputdata-readonly'' (present only while the condition holds)
inputdata-xh-field-input''
itemdata-disabled'' (present only while the condition holds)
itemdata-editing'' (present only while the condition holds)
itemdata-highlighted'' (present only while the condition holds)
itemdata-readonly'' (present only while the condition holds)
item-inputdata-disabled'' (present only while the condition holds)
item-inputdata-editing'' (present only while the condition holds)
item-inputdata-highlighted'' (present only while the condition holds)
item-inputdata-readonly'' (present only while the condition holds)
clear-triggerdata-pressed'' (present only while the condition holds)
clear-triggerdata-xh-action-control''
clear-triggerdata-xh-action-display'has-value'
clear-triggerdata-xh-action-has-value'' (present only while the condition holds)
clear-triggerdata-xh-action-profile'field-inset'
clear-triggerdata-xh-action-sizeprops.size
clear-triggerdata-xh-action-variant'ghost'
countdata-at-max'' (present only while the condition holds)
countdata-disabled'' (present only while the condition holds)

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-tags-input-action-bgclear-trigger--xh-ink-surface
background-color
default
xh-ink-surface
--xh-_action-variant-bg-rest
--xh-tags-input-action-bg-activeclear-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-tags-input-action-bg-hoverclear-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-tags-input-action-fgclear-triggercolordefault--xh-fg-field-clear
--xh-tags-input-action-fg-hoverclear-triggercolordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-fg-default
--xh-tags-input-action-font-sizeclear-triggerfont-sizedefault--xh-text-secondary-size
--xh-tags-input-action-radiusclear-triggerborder-radiusdefault--xh-shape-circle
--xh-tags-input-action-sizeclear-triggerblock-size
inline-size
min-inline-size
default
xh-action-profile=field-inset
--xh-_action-profile-visual-size
--xh-tags-input-control-bgcontrolbackground-colorxh-field-chrome--xh-_field-variant-bg-rest
--xh-tags-input-control-bg-disabledcontrolbackground-colordisabled
xh-field-chrome
--xh-_field-variant-bg-disabled
--xh-tags-input-control-bg-hovercontrolbackground-colordisabled
hover
invalid
loading
not(:focus-within)
not([data-disabled])
not([data-invalid])
not([data-loading])
not([data-readonly])
readonly
xh-field-chrome
--xh-_field-variant-bg-hover
--xh-tags-input-control-bg-readonlycontrolbackground-colorreadonly
xh-field-chrome
--xh-_field-variant-bg-read-only
--xh-tags-input-control-bordercontrolborderxh-field-chrome--xh-_field-variant-border-rest
--xh-tags-input-control-border-at-maxcontrolborder-colorat-max
invalid
not([data-invalid])
--xh-border-at-limit
--xh-tags-input-control-border-focuscontrolborder-color
box-shadow
disabled
focus-within
not([data-disabled])
xh-field-chrome
--xh-_field-variant-border-focus
--xh-tags-input-control-border-hovercontrolborder-colordisabled
hover
invalid
loading
not(:focus-within)
not([data-disabled])
not([data-invalid])
not([data-loading])
not([data-readonly])
readonly
xh-field-chrome
--xh-_field-variant-border-hover
--xh-tags-input-control-border-invalidcontrolborder-colorinvalid
xh-field-chrome
--xh-_field-variant-border-invalid
--xh-tags-input-control-fgcontrolcolorxh-field-chrome--xh-fg-default
--xh-tags-input-control-gapcontrolgapxh-field-chrome--xh-_tags-input-control-gap
--xh-tags-input-control-hcontrolblock-size
min-block-size
has([data-xh-field-input][data-xh-field-layout='multi-tag'])
has([data-xh-field-input][data-xh-field-layout='single-line'])
has([data-xh-field-input][data-xh-field-layout='textarea'])
xh-field-chrome
xh-field-input
xh-field-layout=multi-tag
xh-field-layout=single-line
xh-field-layout=textarea
--xh-_tags-input-control-h
--xh-tags-input-control-max-hcontrolmax-block-sizedefault--xh-viewport-h-sm
--xh-tags-input-control-min-wcontrol
root
min-inline-sizedefault
xh-field-chrome
--xh-control-min-w
--xh-tags-input-control-pscontrolpadding-inline-starthas(> [data-scope='tags-input'][data-part='item'])--xh-space-1
--xh-tags-input-control-pxcontrolpadding-inlinexh-field-chrome--xh-_tags-input-control-px
--xh-tags-input-control-radiuscontrolborder-radiusxh-field-chrome--xh-shape-control
--xh-tags-input-control-shadowcontrolbox-shadowxh-field-chromenone
--xh-tags-input-control-wrootinline-size
min-inline-size
default--xh-control-w
--xh-tags-input-count-fgcountcolordefault--xh-fg-muted
--xh-tags-input-count-fg-at-maxcountcolorat-max--xh-fg-warning
--xh-tags-input-count-fg-disabledcountcolordisabled--xh-fg-disabled
--xh-tags-input-count-font-sizecountfont-sizedefault--xh-text-caption-size
--xh-tags-input-gaplabel
root
gap
margin-block-end
default--xh-space-1
--xh-tags-input-icon-sizecontrol
root
--xh-icon-sizedefault
size=lg
size=sm
xh-field-chrome
--xh-_field-size-glyph-size
--xh-glyph-size-lg
--xh-glyph-size-md
--xh-glyph-size-sm
--xh-tags-input-input-autofill-bginputbox-shadow-webkit-autofill
autofill
xh-field-input
--xh-bg-canvas
--xh-tags-input-input-autofill-fginput-webkit-text-fill-color-webkit-autofill
autofill
xh-field-input
--xh-fg-default
--xh-tags-input-input-basisinputflex-basisdefault6rem
--xh-tags-input-input-fginputcolorxh-field-input--xh-fg-default
--xh-tags-input-input-font-sizeinputfont-sizexh-field-input--xh-_tags-input-input-font-size
--xh-tags-input-input-min-winputmin-inline-sizedefault--xh-control-input-min-w
--xh-tags-input-item-bg-highlightitem
root
backgrounddisabled
highlighted
not([data-disabled])
--xh-_tags-input-accent
--xh-tags-input-item-fg-highlightitem
root
colordisabled
highlighted
not([data-disabled])
--xh-_tags-input-accent-fg
--xh-tags-input-item-font-sizeitem-inputfont-sizedefault--xh-_tags-input-item-font-size
--xh-tags-input-item-hitem-inputmin-block-sizedefault--xh-_tags-input-item-h
--xh-tags-input-item-input-bgitem-inputbackgrounddefault--xh-bg-field
--xh-tags-input-item-input-bg-focusitem-inputbackgroundfocus-within--xh-bg-surface
--xh-tags-input-item-input-borderitem-inputborderdefault--xh-border-control
--xh-tags-input-item-input-border-focusitem-inputborder-colorfocus-within--xh-border-control-focus
--xh-tags-input-item-input-border-invalidcontrol
item-input
border-colorinvalid--xh-border-invalid
--xh-tags-input-item-input-fgitem-inputcolordefault--xh-fg-default
--xh-tags-input-item-pxitem-inputpadding-inlinedefault--xh-_tags-input-item-px
--xh-tags-input-item-pyitem-inputpadding-blockdefault--xh-_tags-input-item-py
--xh-tags-input-item-radiusitem-inputborder-radiusdefault--xh-shape-inset
--xh-tags-input-label-fglabelcolordefault--xh-fg-muted
--xh-tags-input-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-tags-input-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-tags-input-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-tags-input-label-gaplabelmargin-block-enddefault--xh-space-2
--xh-tags-input-placeholder-fginputcolorplaceholder
xh-field-input
--xh-fg-subtle

Released under The MIT License