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

查看生态总览
Skip to content

Mention ​

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="mention": root · label · input · positioner · content · empty · loading · item · item-prefix · item-text · item-description · item-suffix

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-mention>
Vue componentsXhMentionContent XhMentionEmpty XhMentionInput XhMentionItem XhMentionItemDescription XhMentionItemPrefix XhMentionItemSuffix XhMentionItemText XhMentionLabel XhMentionLoading XhMentionPositioner XhMentionRoot
ComposableuseMention
State machinementionMachine
Skin@xihan-ui/styles/mention.css

Props ​

PropTypeRequired
labelledboolean
ariaLabelstring
triggerPrefixstring | string[]
collectionMentionNode[]
valuestring
defaultValuestring
disabledboolean
readOnlyboolean
invalidboolean
loadingboolean
placeholderstring
namestring
loopboolean
placementPlacement
dirDirection
offsetnumber
translationsMentionTranslations
variantControlVariant
toneTone
sizeSize
onValueChange(details: MentionValueChangeDetails) => void
onQueryChange(details: MentionQueryChangeDetails) => void
onItemSelect(details: MentionItemSelectDetails) => void
onOpenChange(details: MentionOpenChangeDetails) => void

MentionNode ​

Elements of collection.

FieldTypeRequired
valuestringYes
labelstring
disabledboolean
toneTone
descriptionstring

Events ​

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

EventPayload
value-changeMentionValueChangeDetails
query-changeMentionQueryChangeDetails
item-selectMentionItemSelectDetails
open-changeMentionOpenChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhMentionRootdefaultMentionRootSlotProps
XhMentionRootlabel—
XhMentionRootitemMentionNodeMeta
XhMentionRootitem-prefixMentionNodeMeta
XhMentionRootitem-suffixMentionNodeMeta
XhMentionRootempty—

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
XhMentionInputasMentionInputHost
XhMentionItemvaluestringYes
XhMentionItemdisabledboolean
XhMentionPositionercontainer() => Element | null
XhMentionRootlabelReactNode
XhMentionRootmultilineboolean
XhMentionRootrenderItem(node: MentionNodeMeta) => ReactNode
XhMentionRootrenderItemPrefix(node: MentionNodeMeta) => ReactNode
XhMentionRootrenderItemSuffix(node: MentionNodeMeta) => ReactNode
XhMentionRootemptyReactNode
XhMentionRootchildrenSlotChildren<MentionRootSlotProps>

State ​

Public state is written to data-state.

PartValues
root'open' | 'closed'
input'open' | 'closed'
positioner'open' | 'closed'
content'open' | 'closed'
empty'open' | 'closed'
loading'open' | 'closed'

The following names are internal to the state machine.

States: open · closed

Events: OPEN · CLOSE · ESCAPE · INPUT.CHANGE · CARET.SYNC · VALUE.SET · ITEM.HIGHLIGHT · ITEM.SELECT · ITEMS.SYNC · FORM.RESET · MENTION.DELETE · PRESS.START · PRESS.END

Guards: canPress

connect API ​

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

MemberType
openboolean
collectionreadonly MentionNodeMeta[]
valuestring
querystring | null
activePrefixstring | null
highlightedValuestring | null
mentionsreadonly MentionRange[]
disabledboolean
emptyboolean
emptyTextstring
loadingTextstring
isHighlighted(value: string) => boolean
setValue(next: string) => void
close() => void
getRootProps() => T['element']
getLabelProps() => T['label']
getInputProps(props?: MentionInputProps) => T['input']
getPositionerProps() => T['element']
getContentProps() => T['element']
getEmptyProps() => T['element']
getLoadingProps() => T['element']
getItemProps(props: MentionItemProps) => T['element']
getItemPrefixProps(props: MentionItemProps) => T['element']
getItemTextProps(props: MentionItemProps) => T['element']
getItemDescriptionProps(props: MentionItemProps) => T['element']
getItemSuffixProps(props: MentionItemProps) => T['element']

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
prefix charactersmention.kbd.trigger
printable charactersmention.kbd.type
ArrowDownmention.kbd.next
ArrowUpmention.kbd.prev
Entermention.kbd.commit
Entermention.kbd.enter-pass
Escapemention.kbd.escape
Tab / Shift+Tabmention.kbd.tab
ArrowLeft / ArrowRight / Home / Endmention.kbd.caret
Backspace / Deletemention.kbd.delete-mention

ARIA ​

These attributes are produced by connect.

PartAttributeValue
inputaria-activedescendantid of the item part | undefined
inputaria-autocomplete'list'
inputaria-controlsid of the content part
inputaria-expandedundefined | 'true' | 'false'
inputaria-haspopup'listbox'
inputaria-invalid'true' | 'false'
inputaria-labelprops.ariaLabel
inputaria-labelledbyid of the label part | undefined
inputroleundefined | 'combobox'
contentaria-busy'true' | undefined
contentaria-hidden!open || undefined
contentaria-labeltranslations.content
contentrole'listbox'
emptyrole'status'
loadingrole'status'
itemaria-disabled'true' | 'false'
itemaria-selected'true' | 'false'
itemrole'option'
item-prefixaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/mention.css is written against [data-scope="mention"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-mention 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-invalid'' (present only while the condition holds)
rootdata-loading'' (present only while the condition holds)
rootdata-readonly'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-state'open' | 'closed'
rootdata-toneprops.tone
rootdata-variantprops.variant
labeldata-disabled'' (present only while the condition holds)
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-state'open' | 'closed'
inputdata-variantprops.variant
inputdata-xh-field-chrome''
inputdata-xh-field-layout'textarea' | 'single-line'
inputdata-xh-field-sizeprops.size
positionerdata-hidden'' (present only while the condition holds)
positionerdata-placementactual placement computed by the positioning engine
positionerdata-positioned'' (present only while the condition holds)
positionerdata-readonly'' (present only while the condition holds)
positionerdata-sizeprops.size
positionerdata-state'open' | 'closed'
positionerdata-toneprops.tone
positionerdata-variantprops.variant
contentdata-placementactual placement computed by the positioning engine
contentdata-state'open' | 'closed'
contentdata-xh-material'frosted'
emptydata-state'open' | 'closed'
loadingdata-loading'' (present only while the condition holds)
loadingdata-state'open' | 'closed'
loadingdata-xh-loading-ring''
itemdata-disabled'' (present only while the condition holds)
itemdata-highlighted'' (present only while the condition holds)
itemdata-pressed'' (present only while the condition holds)
itemdata-tonemetaOf.get(item.value)?.tone
itemdata-xh-collection-context'overlay'
itemdata-xh-collection-item''
itemdata-xh-collection-sizeprops.size
item-prefixdata-disabled'' (present only while the condition holds)
item-prefixdata-highlighted'' (present only while the condition holds)
item-prefixdata-xh-collection-slot'prefix'
item-textdata-disabled'' (present only while the condition holds)
item-textdata-highlighted'' (present only while the condition holds)
item-textdata-xh-collection-slot'text'
item-descriptiondata-disabled'' (present only while the condition holds)
item-descriptiondata-highlighted'' (present only while the condition holds)
item-descriptiondata-xh-collection-slot'description'
item-suffixdata-disabled'' (present only while the condition holds)
item-suffixdata-highlighted'' (present only while the condition holds)
item-suffixdata-xh-collection-slot'suffix'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-mention-content-backdropcontent-webkit-backdrop-filter
backdrop-filter
xh-material=frosted--xh-_material-backdrop
--xh-mention-content-bgcontentbackgroundnot([data-xh-action-control])
xh-material=frosted
--xh-_material-bg
--xh-mention-content-bordercontentbordernot([data-xh-action-control])
xh-material=frosted
--xh-_material-border
--xh-mention-content-fgcontentcolornot([data-xh-action-control])
xh-material=frosted
--xh-_material-fg
--xh-mention-content-gapcontentgapdefault--xh-list-option-gap
--xh-mention-content-highlightcontentbackgroundnot([data-xh-action-control])
xh-material=frosted
--xh-_material-highlight
--xh-mention-content-max-hcontentmax-block-sizedefault--xh-overlay-max-h
--xh-mention-content-max-wcontentmax-inline-sizedefault--xh-overlay-max-w
--xh-mention-content-min-hcontentmin-block-sizedefault--xh-_mention-h
--xh-mention-content-min-wcontentmin-inline-sizedefault--xh-overlay-min-w
--xh-mention-content-pxcontentpadding-inlinedefault--xh-space-1
--xh-mention-content-pycontentpadding-blockdefault--xh-space-1
--xh-mention-content-radiuscontentborder-radiusdefault--xh-shape-overlay
--xh-mention-content-shadowcontentbox-shadownot([data-xh-action-control])
xh-material=frosted
--xh-_material-shadow
--xh-mention-empty-fgemptycolordefault--xh-material-frosted-fg-muted
--xh-mention-empty-font-sizeemptyfont-sizedefault--xh-_mention-font-size
--xh-mention-empty-pxemptypadding-inlinedefault--xh-_mention-item-px
--xh-mention-empty-pyemptypadding-blockdefault--xh-space-3
--xh-mention-input-autofill-bginputbox-shadow-webkit-autofill
autofill
--xh-bg-canvas
--xh-mention-input-autofill-fginput-webkit-text-fill-color-webkit-autofill
autofill
--xh-fg-default
--xh-mention-input-bginputbackground-colorxh-field-chrome--xh-_field-variant-bg-rest
--xh-mention-input-bg-disabledinputbackground-colordisabled
xh-field-chrome
--xh-_field-variant-bg-disabled
--xh-mention-input-bg-hoverinputbackground-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-mention-input-bg-readonlyinputbackground-colorreadonly
xh-field-chrome
--xh-_field-variant-bg-read-only
--xh-mention-input-borderinputborderxh-field-chrome--xh-_field-variant-border-rest
--xh-mention-input-border-focusinputborder-color
box-shadow
disabled
focus-within
not([data-disabled])
xh-field-chrome
--xh-_field-variant-border-focus
--xh-mention-input-border-hoverinputborder-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-mention-input-border-invalidinputborder-colorinvalid
xh-field-chrome
--xh-_field-variant-border-invalid
--xh-mention-input-fginputcolorxh-field-chrome--xh-fg-default
--xh-mention-input-font-sizeinputfont-sizedefault--xh-_mention-font-size
--xh-mention-input-hinputblock-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-_mention-h
--xh-mention-input-min-winput
root
min-inline-sizedefault
xh-field-chrome
--xh-control-min-w
--xh-mention-input-pxinputpadding-inlinexh-field-chrome--xh-_mention-px
--xh-mention-input-radiusinputborder-radiusxh-field-chrome--xh-shape-control
--xh-mention-input-shadowinputbox-shadowxh-field-chromenone
--xh-mention-input-wrootinline-size
min-inline-size
default--xh-control-w
--xh-mention-item-bg-hoveritembackground-colordisabled
error
highlighted
hover
is(:focus-visible, [data-highlighted])
is([aria-selected='true'], [data-selected])
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
selected
xh-collection-context=overlay
--xh-bg-subtle
--xh-mention-item-bg-presseditembackground-colordisabled
error
is(:active, [data-pressed])
is([aria-selected='true'], [data-selected])
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
pressed
selected
xh-collection-context=overlay
--xh-bg-subtle-hover
--xh-mention-item-fgitemcolordefault
disabled
error
highlighted
hover
is(:active, [data-pressed])
is(:focus-visible, [data-highlighted])
is([aria-selected='true'], [data-selected])
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
pressed
selected
xh-collection-context=overlay
--xh-material-frosted-fg
--xh-mention-item-font-sizeitemfont-sizedefault--xh-_mention-font-size
--xh-mention-item-gapitemmargin-inline-end
margin-inline-start
default
xh-collection-slot=indicator
xh-collection-slot=prefix
xh-collection-slot=shortcut
xh-collection-slot=suffix
--xh-_mention-gap
--xh-mention-item-hitemmin-block-sizedefault--xh-_mention-item-h
--xh-mention-item-leadingitemline-heightdefault--xh-leading-normal
--xh-mention-item-pxitempadding-inlinedefault--xh-_mention-item-px
--xh-mention-item-pyitempadding-blockdefault--xh-_mention-item-py
--xh-mention-item-radiusitemborder-radiusdefault--xh-shape-inset
--xh-mention-label-fglabelcolordefault--xh-fg-muted
--xh-mention-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-mention-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-mention-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-mention-label-gaplabelmargin-block-enddefault--xh-space-2
--xh-mention-layerpositionerz-indexdefault--xh-_layer
--xh-mention-loading-fgloadingcolordefault--xh-material-frosted-fg-muted
--xh-mention-loading-font-sizeloadingfont-sizedefault--xh-_mention-font-size
--xh-mention-loading-pxloadingpadding-inlinedefault--xh-_mention-item-px
--xh-mention-loading-pyloadingpadding-blockdefault--xh-space-3
--xh-mention-placeholder-fginputcolorplaceholder--xh-fg-subtle
--xh-mention-textarea-pyinputpadding-blockxh-field-layout=textarea--xh-space-1

Released under The MIT License