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

查看生态总览
Skip to content

Command ​

Overlays 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="command": trigger · backdrop · positioner · content · input · list · group · group-label · item · item-prefix · item-text · item-description · item-shortcut · item-suffix · empty · loading · footer

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-command>
Vue componentsXhCommandContent XhCommandEmpty XhCommandFooter XhCommandGroup XhCommandGroupLabel XhCommandInput XhCommandItem XhCommandItemDescription XhCommandItemPrefix XhCommandItemShortcut XhCommandItemSuffix XhCommandItemText XhCommandList XhCommandLoading XhCommandRoot XhCommandTrigger
ComposableuseCommand
State machinecommandMachine
Skin@xihan-ui/styles/command.css

Props ​

PropTypeRequired
collectionreadonly CommandNode[]
groupsreadonly CommandGroup[]
openboolean
defaultOpenboolean
inputValuestring
defaultInputValuestring
filterboolean
caseSensitiveboolean
closeOnSelectboolean
modalboolean
closeOnEscapeboolean
closeOnInteractOutsideboolean
restoreFocusboolean
loopboolean
loadingboolean
placeholderstring
dirDirection
sizeSize
variantOverlayBackdropVariant
translationsPartial<CommandTranslations>
onOpenChange(details: CommandOpenChangeDetails) => void
onInputValueChange(details: CommandInputValueChangeDetails) => void
onItemSelect(details: CommandItemSelectDetails) => void

CommandNode ​

Elements of collection.

FieldTypeRequired
valuestringYes
labelstring
keywordsreadonly string[]
groupstring
disabledboolean
toneTone
descriptionstring
shortcutstring

CommandGroup ​

Elements of groups.

FieldTypeRequired
valuestringYes
labelstring

Events ​

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

EventPayload
open-changeCommandOpenChangeDetails
input-value-changeCommandInputValueChangeDetails
item-selectCommandItemSelectDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhCommandRootdefaultCommandRootSlotProps
XhCommandRoottrigger—
XhCommandRootitemCommandNodeMeta
XhCommandRootitem-prefixCommandNodeMeta
XhCommandRootitem-suffixCommandNodeMeta
XhCommandRootempty—
XhCommandRootfooter—

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
XhCommandContentcontainer() => Element | null
XhCommandGroupvaluestringYes
XhCommandItemvaluestringYes
XhCommandItemdisabledboolean
XhCommandRootemptyReactNode
XhCommandRoottriggerReactNode
XhCommandRootfooterReactNode
XhCommandRootrenderItem(node: CommandNodeMeta) => ReactNode
XhCommandRootrenderItemPrefix(node: CommandNodeMeta) => ReactNode
XhCommandRootrenderItemSuffix(node: CommandNodeMeta) => ReactNode
XhCommandRootchildrenSlotChildren<CommandRootSlotProps>

State ​

Public state is written to data-state.

PartValues
trigger'open' | 'closed'
backdrop'open' | 'closed'
positioner'open' | 'closed'
content'open' | 'closed'
input'open' | 'closed'
list'open' | 'closed'
empty'open' | 'closed'
loading'open' | 'closed'
footer'open' | 'closed'

The following names are internal to the state machine.

States: open · closed

Events: OPEN · TOGGLE · CLOSE · CONTROLLED.OPEN · CONTROLLED.CLOSE · INPUT.CHANGE · INPUT.SET · ITEM.HIGHLIGHT · HIGHLIGHT.CLEAR · ITEM.SELECT · PRESS.START · PRESS.END · ARRIVALS.TRACKED

Guards: isOpenControlled · keepsOpenOnSelect · canPress

connect API ​

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

MemberType
openboolean
inputValuestring
groupsreadonly CommandGroupMeta[]
resultsreadonly CommandNodeMeta[]
highlightedValuestring | null
emptyboolean
loadingboolean
setOpen(next: boolean) => void
setInputValue(next: string) => void
select(value: string) => void
getTriggerProps() => T['button']
getBackdropProps() => T['element']
getPositionerProps() => T['element']
getContentProps() => T['element']
getInputProps() => T['input']
getListProps() => T['element']
getGroupProps(props: CommandGroupProps) => T['element']
getGroupLabelProps(props: CommandGroupProps) => T['element']
getItemProps(props: CommandItemProps) => T['element']
getItemPrefixProps(props: CommandItemProps) => T['element']
getItemTextProps(props: CommandItemProps) => T['element']
getItemDescriptionProps(props: CommandItemProps) => T['element']
getItemShortcutProps(props: CommandItemProps) => T['element']
getItemSuffixProps(props: CommandItemProps) => T['element']
getEmptyProps() => T['element']
getLoadingProps() => T['element']
getFooterProps() => 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
Enter / Spacecommand.kbd.open-on-trigger
Escapecommand.kbd.escape
ArrowDowncommand.kbd.next
ArrowUpcommand.kbd.prev
Homecommand.kbd.first
Endcommand.kbd.last
Entercommand.kbd.select
Entercommand.kbd.press
Tabcommand.kbd.tab

ARIA ​

These attributes are produced by connect.

PartAttributeValue
triggeraria-controlsid of the content part
triggeraria-expanded'true' | 'false'
triggeraria-haspopup'dialog'
contentaria-hidden!open || undefined
contentaria-labeltranslations.title
contentaria-modal'true' | 'false'
contentrole'dialog'
inputaria-activedescendantid of the item part | undefined
inputaria-autocomplete'list'
inputaria-controlsid of the list part
inputaria-expanded'true'
inputaria-haspopup'listbox'
inputaria-labeltranslations.input
inputrole'combobox'
listaria-busy'true' | undefined
listaria-labeltranslations.list
listrole'listbox'
grouparia-labelledbyid of the group-label part
grouprole'group'
itemaria-disabled'true' | 'false'
itemaria-selected'true' | 'false'
itemrole'option'
item-prefixaria-hidden'true'
item-shortcutaria-hidden'true'
emptyrole'status'
loadingrole'status'

Style reference ​

Skin ​

@xihan-ui/styles/command.css is written against [data-scope="command"][data-part="trigger"] part selectors; the published build uses the mount class .xh-scope-command 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
triggerdata-state'open' | 'closed'
backdropdata-instant'' (present only while the condition holds)
backdropdata-state'open' | 'closed'
backdropdata-variantprops.variant
positionerdata-positioned''
positionerdata-sizeprops.size
positionerdata-state'open' | 'closed'
contentdata-instant'' (present only while the condition holds)
contentdata-sizeprops.size
contentdata-state'open' | 'closed'
inputdata-state'open' | 'closed'
inputdata-xh-field-input''
listdata-instant'' (present only while the condition holds)
listdata-state'open' | 'closed'
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-shortcutdata-disabled'' (present only while the condition holds)
item-shortcutdata-highlighted'' (present only while the condition holds)
item-shortcutdata-xh-collection-slot'shortcut'
item-suffixdata-disabled'' (present only while the condition holds)
item-suffixdata-highlighted'' (present only while the condition holds)
item-suffixdata-xh-collection-slot'suffix'
emptydata-state'open' | 'closed'
loadingdata-loading'' (present only while the condition holds)
loadingdata-state'open' | 'closed'
loadingdata-xh-loading-ring''
footerdata-state'open' | 'closed'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-command-backdrop-bgbackdropbackgrounddefault--xh-bg-overlay
--xh-command-backdrop-blurbackdropbackdrop-filtervariant=blur--xh-overlay-backdrop-blur
--xh-command-backdrop-layerbackdropz-indexdefault--xh-_layer
--xh-command-bgcontentbackgrounddefault--xh-material-elevated-bg
--xh-command-bordercontentborderdefault--xh-material-elevated-border
--xh-command-empty-fgemptycolordefault--xh-fg-muted
--xh-command-empty-font-sizeemptyfont-sizedefault--xh-_command-font-size
--xh-command-empty-pxemptypadding-inlinedefault--xh-_command-px
--xh-command-empty-pyemptypadding-blockdefault--xh-space-3
--xh-command-fgcontentcolordefault--xh-material-elevated-fg
--xh-command-footer-borderfooterborder-block-startdefault--xh-material-elevated-border
--xh-command-footer-fgfootercolordefault--xh-fg-muted
--xh-command-footer-font-sizefooterfont-sizedefault--xh-text-caption-size
--xh-command-footer-gapfootergapdefault--xh-space-2
--xh-command-footer-pxfooterpadding-inlinedefault--xh-_command-px
--xh-command-footer-pyfooterpadding-blockdefault--xh-space-2
--xh-command-group-gapgroupgapdefault--xh-list-option-gap
--xh-command-group-label-fggroup-labelcolordefault--xh-fg-subtle
--xh-command-group-label-font-sizegroup-labelfont-sizedefault--xh-text-caption-size
--xh-command-group-label-font-weightgroup-labelfont-weightdefault--xh-font-weight-regular
--xh-command-group-label-pxgroup-labelpadding-inlinedefault--xh-_command-px
--xh-command-group-label-pygroup-labelpadding-blockdefault--xh-space-1
--xh-command-group-spacinggroupmargin-block-startdefault--xh-space-2
--xh-command-icon-sizecontent
positioner
--xh-icon-sizeis([data-part='positioner'], [data-part='content'])
size=lg
size=sm
--xh-glyph-size-lg
--xh-glyph-size-md
--xh-glyph-size-sm
--xh-command-input-autofill-bginputbox-shadow-webkit-autofill
autofill
--xh-bg-surface
--xh-command-input-autofill-fginput-webkit-text-fill-color-webkit-autofill
autofill
--xh-fg-default
--xh-command-input-borderinputborder-block-enddefault--xh-material-elevated-border
--xh-command-input-fginputcolordefault--xh-fg-default
--xh-command-input-font-sizeinputfont-sizedefault--xh-_command-font-size
--xh-command-input-hinputblock-sizedefault--xh-_command-input-h
--xh-command-input-pxinputpadding-inlinedefault--xh-_command-px
--xh-command-inset-block-startpositionerpadding-block-startdefault--xh-space-8
--xh-command-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-command-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-command-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-fg-default
--xh-command-item-font-sizeitemfont-sizedefault--xh-_command-font-size
--xh-command-item-gapitemgapdefault--xh-_command-gap
--xh-command-item-hitemmin-block-sizedefault--xh-_command-item-h
--xh-command-item-leadingitemline-heightdefault--xh-leading-normal
--xh-command-item-pxitempadding-inlinedefault--xh-_command-px
--xh-command-item-pyitempadding-blockdefault--xh-_command-item-py
--xh-command-item-radiusitemborder-radiusdefault--xh-shape-inset
--xh-command-layerpositionerz-indexdefault--xh-_layer
--xh-command-list-gaplistgapdefault--xh-list-option-gap
--xh-command-list-pxlistpadding-inlinedefault--xh-space-1
--xh-command-list-pylistpadding-blockdefault--xh-space-1
--xh-command-loading-fgloadingcolordefault--xh-fg-muted
--xh-command-loading-font-sizeloadingfont-sizedefault--xh-_command-font-size
--xh-command-loading-pxloadingpadding-inlinedefault--xh-_command-px
--xh-command-loading-pyloadingpadding-blockdefault--xh-space-3
--xh-command-max-hcontentmax-block-sizedefault--xh-overlay-max-h
--xh-command-max-wcontentmax-inline-sizedefault--xh-_command-max-w
--xh-command-placeholder-fginputcolorplaceholder
xh-field-input
--xh-fg-subtle
--xh-command-positioner-pbpositionerpadding-block-enddefault--xh-space-4
--xh-command-positioner-pxpositionerpadding-inlinedefault--xh-space-4
--xh-command-radiuscontentborder-radiusdefault--xh-shape-overlay
--xh-command-shadowcontentbox-shadowdefault--xh-material-elevated-shadow

Released under The MIT License