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

查看生态总览
Skip to content

Listbox ​

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="listbox": root · label · content · item · item-prefix · item-text · item-description · item-suffix · item-indicator · group · group-label · empty · loading · load-more-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-listbox>
Vue componentsXhListboxContent XhListboxEmpty XhListboxGroup XhListboxGroupLabel XhListboxItem XhListboxItemDescription XhListboxItemIndicator XhListboxItemPrefix XhListboxItemSuffix XhListboxItemText XhListboxLabel XhListboxLoadMoreTrigger XhListboxLoading XhListboxRoot
ComposableuseListbox
State machinelistboxMachine
Skin@xihan-ui/styles/listbox.css

Props ​

PropTypeRequired
labelledboolean
ariaLabelstring
collectionListboxNode<V>[]
valueKeySelectionValueKey<V>
virtualizerCollectionVirtualizer
valueV | V[]
defaultValueV | V[]
selectionModeListboxSelectionMode
disabledboolean
readOnlyboolean
loadingboolean
invalidboolean
toneTone
sizeSize
loopboolean
dirDirection
orientationOrientation
typeaheadboolean
translationsPartial<ListboxTranslations>
onValueChange(details: ListboxValueChangeDetails<V>) => void

ListboxNode ​

Elements of collection.

FieldTypeRequired
valueVYes
labelstring
disabledboolean
toneTone
descriptionstring

Events ​

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

EventPayload
value-changeListboxValueChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhListboxRootdefaultListboxRootSlotProps<V>
XhListboxRootlabel—
XhListboxRootempty—
XhListboxRootitemListboxNodeMeta<V>
XhListboxRootitem-prefixListboxNodeMeta<V>
XhListboxRootitem-suffixListboxNodeMeta<V>

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
XhListboxGroupvaluestringYes
XhListboxItemvalueunknownYes
XhListboxItemdisabledboolean
XhListboxRootlabelReactNode
XhListboxRootemptyReactNode
XhListboxRootrenderItem(node: ListboxNodeMeta<V>) => ReactNode
XhListboxRootrenderItemPrefix(node: ListboxNodeMeta<V>) => ReactNode
XhListboxRootrenderItemSuffix(node: ListboxNodeMeta<V>) => ReactNode
XhListboxRootchildrenSlotChildren<ListboxRootSlotProps<V>>

State ​

Public state is written to data-state.

PartValues
item'checked' | 'unchecked'
item-prefix'checked' | 'unchecked'
item-text'checked' | 'unchecked'
item-description'checked' | 'unchecked'
item-suffix'checked' | 'unchecked'
item-indicator'checked' | 'unchecked'

The following names are internal to the state machine.

States: idle

Events: VALUE.SET · VALUE.CLEAR · ITEM.SELECT · ITEM.TOGGLE · ITEM.FOCUS · FOCUS.CLEAR · LIST.BLUR · PRESS.START · PRESS.END

Guards: canPress

connect API ​

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

MemberType
valueV[]
valueKeysstring[]
collectionreadonly ListboxNodeMeta<V>[]
selectionModeListboxSelectionMode
focusedValueV | null
disabledboolean
readOnlyboolean
invalidboolean
loadingboolean
translationsListboxTranslations
isSelected(value: V) => boolean
setValue(next: V[]) => void
select(value: V) => void
toggle(value: V) => void
getRootProps() => T['element']
getLabelProps() => T['element']
getContentProps() => T['element']
getEmptyProps() => T['element']
getLoadingProps() => T['element']
getLoadMoreTriggerProps() => T['element']
getGroupProps(props: ListboxGroupProps) => T['element']
getGroupLabelProps(props: ListboxGroupProps) => T['element']
getItemProps(props: ListboxItemProps<V>) => T['element']
getItemPrefixProps(props: ListboxItemProps<V>) => T['element']
getItemTextProps(props: ListboxItemProps<V>) => T['element']
getItemDescriptionProps(props: ListboxItemProps<V>) => T['element']
getItemSuffixProps(props: ListboxItemProps<V>) => T['element']
getItemIndicatorProps(props: ListboxItemProps<V>) => 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
Tab / Shift+Tablistbox.kbd.tab
ArrowDownlistbox.kbd.next
ArrowUplistbox.kbd.prev
Homelistbox.kbd.first
Endlistbox.kbd.last
Enter / Spacelistbox.kbd.select
Space / Enter / Ctrl+Spacelistbox.kbd.toggle
Shift+ArrowDown / Shift+ArrowUplistbox.kbd.extend
Ctrl+A / Cmd+Alistbox.kbd.select-all
Enter / Spacelistbox.kbd.press
any single printable characterlistbox.kbd.typeahead

ARIA ​

These attributes are produced by connect.

PartAttributeValue
contentaria-busy'true' | undefined
contentaria-disabled'true' | 'false'
contentaria-invalid'true' | 'false'
contentaria-labelprops.ariaLabel
contentaria-labelledbyid of the label part | undefined
contentaria-multiselectable'true' | 'false'
contentaria-orientationprops.orientation
contentaria-readonly'true' | 'false'
contentrole'listbox'
itemaria-disabled'true' | 'false'
itemaria-selected'true' | 'false'
itemrole'option'
item-prefixaria-hidden'true'
item-indicatoraria-hidden'true'
grouparia-labelledbyid of the group-label part
grouprole'group'

Style reference ​

Skin ​

@xihan-ui/styles/listbox.css is written against [data-scope="listbox"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-listbox 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-orientationprops.orientation
rootdata-readonly'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-toneprops.tone
labeldata-disabled'' (present only while the condition holds)
contentdata-disabled'' (present only while the condition holds)
contentdata-invalid'' (present only while the condition holds)
contentdata-orientationprops.orientation
contentdata-readonly'' (present only while the condition holds)
contentdata-xh-virtualized'' (present only while the condition holds)
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-state'checked' | 'unchecked'
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-state'checked' | 'unchecked'
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-state'checked' | 'unchecked'
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-state'checked' | 'unchecked'
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-state'checked' | 'unchecked'
item-suffixdata-xh-collection-slot'suffix'
item-indicatordata-disabled'' (present only while the condition holds)
item-indicatordata-highlighted'' (present only while the condition holds)
item-indicatordata-state'checked' | 'unchecked'
item-indicatordata-xh-collection-slot'indicator'
groupdata-disabled'' (present only while the condition holds)
group-labeldata-disabled'' (present only while the condition holds)
emptydata-disabled'' (present only while the condition holds)
loadingdata-disabled'' (present only while the condition holds)
loadingdata-loading'' (present only while the condition holds)
loadingdata-xh-loading-ring''
load-more-triggerdata-disabled'' (present only while the condition holds)
load-more-triggerdata-loading'' (present only while the condition holds)
load-more-triggerdata-pressed'' (present only while the condition holds)
load-more-triggerdata-xh-action-control''
load-more-triggerdata-xh-action-display'always'
load-more-triggerdata-xh-action-profile'row'
load-more-triggerdata-xh-action-sizeprops.size
load-more-triggerdata-xh-action-variant'ghost'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-listbox-content-bgcontentbackgrounddefault--xh-bg-surface
--xh-listbox-content-bordercontentborderdefault--xh-border-default
--xh-listbox-content-border-invalidcontentborder-colorinvalid--xh-border-invalid
--xh-listbox-content-fgcontentcolordefault--xh-fg-default
--xh-listbox-content-gapcontentgapdefault--xh-list-option-gap
--xh-listbox-content-max-hcontentmax-block-sizedefault--xh-viewport-h-md
--xh-listbox-content-pxcontentpadding-inlinedefault--xh-space-1
--xh-listbox-content-pycontentpadding-blockdefault--xh-space-1
--xh-listbox-content-radiuscontentborder-radiusdefault--xh-shape-surface
--xh-listbox-empty-fgemptycolordefault--xh-fg-muted
--xh-listbox-empty-font-sizeemptyfont-sizedefault--xh-_listbox-font-size
--xh-listbox-empty-pxemptypadding-inlinedefault--xh-_listbox-item-px
--xh-listbox-empty-pyemptypadding-blockdefault--xh-space-3
--xh-listbox-gaprootgapdefault--xh-space-2
--xh-listbox-group-gapgroupgapdefault--xh-list-option-gap
--xh-listbox-group-label-fggroup-labelcolordefault--xh-fg-muted
--xh-listbox-group-label-font-sizegroup-labelfont-sizedefault--xh-text-caption-size
--xh-listbox-group-label-font-weightgroup-labelfont-weightdefault--xh-font-weight-medium
--xh-listbox-group-label-pxgroup-labelpadding-inlinedefault--xh-_listbox-item-px
--xh-listbox-group-label-pygroup-labelpadding-blockdefault--xh-space-1
--xh-listbox-group-spacinggroupmargin-block-starthas([data-scope='listbox'][data-part='item']:not([hidden])
not([data-scope='listbox'][data-part='content'] [hidden] *)
--xh-space-1_5
--xh-listbox-icon-sizeitem
root
--xh-icon-sizedefault
size=lg
size=sm
--xh-_collection-glyph-size
--xh-glyph-size-lg
--xh-glyph-size-md
--xh-glyph-size-sm
--xh-listbox-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-listbox-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-listbox-item-check-fgitemcolordisabled
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
state=checked
xh-collection-context=overlay
xh-collection-slot=indicator
--xh-listbox-item-indicator-fg
--xh-listbox-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-listbox-item-fg-selecteditemcolordisabled
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-listbox-item-fg
--xh-listbox-item-font-sizeitemfont-sizedefault--xh-_listbox-font-size
--xh-listbox-item-font-weight-selecteditemfont-weightdisabled
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-font-weight-medium
--xh-listbox-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-_listbox-gap
--xh-listbox-item-indicator-fgitemcolordisabled
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
state=checked
xh-collection-context=overlay
xh-collection-slot=indicator
--xh-_listbox-accent
--xh-listbox-item-indicator-sizeitem-indicator--xh-icon-size
block-size
inline-size
default--xh-control-indicator-size
--xh-listbox-item-leadingitemline-heightdefault--xh-leading-normal
--xh-listbox-item-pxitempadding-inlinedefault--xh-_listbox-item-px
--xh-listbox-item-pyitempadding-blockdefault--xh-_listbox-item-py
--xh-listbox-item-radiusitemborder-radiusdefault--xh-shape-inset
--xh-listbox-label-fglabelcolordefault--xh-fg-muted
--xh-listbox-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-listbox-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-listbox-load-more-trigger-bg-hoverload-more-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-listbox-load-more-trigger-fgload-more-triggercolordefault
disabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_tone-fg
--xh-listbox-load-more-trigger-font-sizeload-more-triggerfont-sizedefault--xh-_listbox-font-size
--xh-listbox-load-more-trigger-gapload-more-triggergapdefault--xh-_listbox-gap
--xh-listbox-load-more-trigger-pxload-more-triggerpadding-inlinedefault--xh-_listbox-item-px
--xh-listbox-load-more-trigger-pyload-more-triggerpadding-blockxh-action-profile=row--xh-_listbox-item-py
--xh-listbox-load-more-trigger-radiusload-more-triggerborder-radiusdefault--xh-shape-control
--xh-listbox-loading-fgloadingcolordefault--xh-fg-muted
--xh-listbox-loading-font-sizeloadingfont-sizedefault--xh-_listbox-font-size
--xh-listbox-loading-pxloadingpadding-inlinedefault--xh-_listbox-item-px
--xh-listbox-loading-pyloadingpadding-blockdefault--xh-space-3

Released under The MIT License