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

查看生态总览
Skip to content

Select ​

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="select": root · label · control · trigger · value-text · indicator · clear-trigger · tag-list · positioner · content · list · footer · group · group-label · item · item-prefix · item-text · item-description · item-suffix · item-indicator · empty · loading · error · retry-trigger · hidden-select

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-select>
Vue componentsXhSelectClearTrigger XhSelectContent XhSelectControl XhSelectEmpty XhSelectError XhSelectFooter XhSelectGroup XhSelectGroupLabel XhSelectIndicator XhSelectItem XhSelectItemDeleteTrigger XhSelectItemDescription XhSelectItemIndicator XhSelectItemPrefix XhSelectItemSuffix XhSelectItemText XhSelectLabel XhSelectList XhSelectLoading XhSelectOverflowTag XhSelectPositioner XhSelectRetryTrigger XhSelectRoot XhSelectTag XhSelectTagLabel XhSelectTagList XhSelectTrigger XhSelectValueText
ComposableuseSelect
State machineselectMachine
Skin@xihan-ui/styles/select.css

Props ​

PropTypeRequired
labelledboolean
ariaLabelstring
collectionSelectNode<V>[]
valueKeySelectionValueKey<V>
virtualizerCollectionVirtualizer
lazyMountboolean
valueV | V[] | null
defaultValueV | V[] | null
multipleboolean
openboolean
defaultOpenboolean
disabledboolean
readOnlyboolean
invalidboolean
loadingboolean
errorboolean
translationsPartial<SelectTranslations>
maxTagCountnumber
requiredboolean
namestring
placeholderstring
placementPlacement
offsetnumber
loopboolean
dirDirection
variantControlVariant
toneTone
sizeSize
onValueChange(details: SelectValueChangeDetails<V>) => void
onClear() => void
onOpenChange(details: SelectOpenChangeDetails) => void
onRetry() => void

SelectNode ​

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-changeSelectValueChangeDetails
clear``
open-changeSelectOpenChangeDetails
retry``

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhSelectRootdefaultSelectRootSlotProps<V>
XhSelectRootlabel—
XhSelectRootempty—
XhSelectRootitemSelectNodeMeta<V>
XhSelectRootitem-prefixSelectNodeMeta<V>
XhSelectRootitem-suffixSelectNodeMeta<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
XhSelectGroupvaluestringYes
XhSelectItemvalueunknownYes
XhSelectItemdisabledboolean
XhSelectPositionercontainer() => Element | null
XhSelectRootvirtualboolean
XhSelectRootestimateSizenumber
XhSelectRootlabelReactNode
XhSelectRootemptyReactNode
XhSelectRootclearableboolean
XhSelectRootrenderItem(node: SelectNodeMeta<V>) => ReactNode
XhSelectRootrenderItemPrefix(node: SelectNodeMeta<V>) => ReactNode
XhSelectRootrenderItemSuffix(node: SelectNodeMeta<V>) => ReactNode
XhSelectRootchildrenSlotChildren<SelectRootSlotProps<V>>
XhSelectTagvalueunknownYes

State ​

Public state is written to data-state.

PartValues
root'open' | 'closed'
control'open' | 'closed'
trigger'open' | 'closed'
indicator'open' | 'closed'
positioner'open' | 'closed'
content'open' | 'closed'
list'open' | 'closed'
footer'open' | 'closed'
item'checked' | 'unchecked'
item-prefix'checked' | 'unchecked'
item-text'checked' | 'unchecked'
item-description'checked' | 'unchecked'
item-suffix'checked' | 'unchecked'
item-indicator'checked' | 'unchecked'
empty'open' | 'closed'
loading'open' | 'closed'
error'open' | 'closed'

The following names are internal to the state machine.

States: open · closed

Events: OPEN · TOGGLE · CLOSE · CONTROLLED.OPEN · CONTROLLED.CLOSE · ITEM.HIGHLIGHT · HIGHLIGHT.CLEAR · ITEM.LOST · ITEM.SELECT · VALUE.SET · VALUE.CLEAR · FORM.RESET · PRESS.START · PRESS.END · TAG_LIST.TRACKED

Guards: isOpenControlled · isMultiple · isReadOnly · canPress

connect API ​

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

MemberType
openboolean
collectionreadonly SelectNodeMeta<V>[]
valueV[]
valueKeysstring[]
valueTextstring[]
displayTextstring
multipleboolean
invalidboolean
errorboolean
translationsSelectTranslations
readOnlyboolean
canClearboolean
tagsSelectTagMeta<V>[]
overflowCountnumber
overflowTextstring
highlightedValueV | null
setOpen(next: boolean) => void
setValue(next: V | V[]) => void
clear() => void
deselect(value: V) => void
getRootProps() => T['element']
getLabelProps() => T['element']
getControlProps() => T['element']
getTriggerProps() => T['button']
getValueTextProps() => T['element']
getIndicatorProps() => T['element']
getClearTriggerProps() => T['button']
getTagListProps() => T['element']
getTagProps(props: SelectTagProps<V>) => T['element']
getTagLabelProps() => T['element']
getOverflowTagProps() => T['element']
getItemDeleteTriggerProps(props: SelectTagProps<V>) => T['button']
getPositionerProps() => T['element']
getContentProps() => T['element']
isContentMounted() => boolean
getListProps() => T['element']
getFooterProps() => T['element']
getEmptyProps() => T['element']
getLoadingProps() => T['element']
getErrorProps() => T['element']
getRetryTriggerProps() => T['button']
getGroupProps(props: SelectGroupProps) => T['element']
getGroupLabelProps(props: SelectGroupProps) => T['element']
getItemProps(props: SelectItemProps<V>) => T['element']
getItemPrefixProps(props: SelectItemProps<V>) => T['element']
getItemTextProps(props: SelectItemProps<V>) => T['element']
getItemDescriptionProps(props: SelectItemProps<V>) => T['element']
getItemSuffixProps(props: SelectItemProps<V>) => T['element']
getItemIndicatorProps(props: SelectItemProps<V>) => T['element']
getHiddenSelectProps() => T['select']

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 / Spaceselect.kbd.open
ArrowDownselect.kbd.open-next
ArrowUpselect.kbd.open-prev
any single printable characterselect.kbd.trigger-typeahead
Deleteselect.kbd.clear
Backspaceselect.kbd.backspace
ArrowDownselect.kbd.next
ArrowUpselect.kbd.prev
Homeselect.kbd.first
Endselect.kbd.last
any single printable characterselect.kbd.typeahead
Enter / Spaceselect.kbd.select
Enter / Spaceselect.kbd.press
Enter / Spaceselect.kbd.multi-select
Enter / Spaceselect.kbd.retry
Escapeselect.kbd.escape
Tab / Shift+Tabselect.kbd.tab

ARIA ​

These attributes are produced by connect.

PartAttributeValue
triggeraria-controlsid of the content part
triggeraria-expanded'true' | 'false'
triggeraria-haspopup'listbox'
triggeraria-invalid'true' | 'false'
triggeraria-labelprops.ariaLabel
triggeraria-labelledbyid of the label part id of the value-text part | id of the trigger part id of the value-text part | id of the value-text part
triggeraria-readonly'true' | 'false'
triggerrole'combobox'
indicatoraria-hidden'true'
clear-triggeraria-labeltranslations.clearTrigger
contentaria-hidden!open || undefined
listaria-busy'true' | undefined
listaria-labeltranslations.content
listaria-labelledbyid of the label part id of the value-text part | id of the trigger part id of the value-text part | id of the value-text part
listaria-multiselectable'true' | 'false'
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-indicatoraria-hidden'true'
errorrole'alert'
hidden-selectaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/select.css is written against [data-scope="select"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-select 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)
controldata-disabled'' (present only while the condition holds)
controldata-invalid'' (present only while the condition holds)
controldata-readonly'' (present only while the condition holds)
controldata-state'open' | 'closed'
controldata-variantprops.variant
controldata-xh-action-owner''
controldata-xh-field-chrome''
controldata-xh-field-sizeprops.size
triggerdata-disabled'' (present only while the condition holds)
triggerdata-invalid'' (present only while the condition holds)
triggerdata-placeholder'' (present only while the condition holds)
triggerdata-readonly'' (present only while the condition holds)
triggerdata-state'open' | 'closed'
value-textdata-disabled'' (present only while the condition holds)
value-textdata-placeholder'' (present only while the condition holds)
indicatordata-clearable'' (present only while the condition holds)
indicatordata-disabled'' (present only while the condition holds)
indicatordata-state'open' | 'closed'
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'
tag-listdata-disabled'' (present only while the condition holds)
tag-listdata-instant'' (present only while the condition holds)
tag-listdata-xh-tag-list''
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-sizeprops.size
positionerdata-state'open' | 'closed'
positionerdata-toneprops.tone
positionerdata-variantprops.variant
contentdata-instant'' (present only while the condition holds)
contentdata-placementactual placement computed by the positioning engine
contentdata-state'open' | 'closed'
contentdata-xh-material'frosted'
listdata-state'open' | 'closed'
footerdata-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-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-state'checked' | 'unchecked'
item-prefixdata-xh-collection-slot'prefix'
item-textdata-disabled'' (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-state'checked' | 'unchecked'
item-descriptiondata-xh-collection-slot'description'
item-suffixdata-disabled'' (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-state'checked' | 'unchecked'
item-indicatordata-xh-collection-slot'indicator'
emptydata-state'open' | 'closed'
loadingdata-loading'' (present only while the condition holds)
loadingdata-state'open' | 'closed'
loadingdata-xh-loading-ring''
errordata-state'open' | 'closed'
retry-triggerdata-xh-action-control''
retry-triggerdata-xh-action-display'always'
retry-triggerdata-xh-action-profile'text'
retry-triggerdata-xh-action-sizeprops.size
retry-triggerdata-xh-action-variant'ghost'
overflow-tagdata-countString(overflowCount)
tagdata-valuev

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-select-action-bgclear-trigger--xh-ink-surface
background-color
default
xh-ink-surface
--xh-_action-variant-bg-rest
--xh-select-action-bg-activeclear-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-select-action-bg-hoverclear-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-select-action-fgclear-triggercolordefault--xh-fg-field-clear
--xh-select-action-fg-hoverclear-triggercolordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-fg-default
--xh-select-action-font-sizeclear-triggerfont-sizedefault--xh-text-secondary-size
--xh-select-action-radiusclear-triggerborder-radiusdefault--xh-shape-circle
--xh-select-action-sizeclear-trigger
indicator
block-size
inline-size
min-inline-size
default
xh-action-profile=field-inset
--xh-_action-profile-visual-size
--xh-control-action-size
--xh-select-content-backdropcontent-webkit-backdrop-filter
backdrop-filter
xh-material=frosted--xh-_material-backdrop
--xh-select-content-bgcontentbackgroundnot([data-xh-action-control])
xh-material=frosted
--xh-_material-bg
--xh-select-content-bordercontentbordernot([data-xh-action-control])
xh-material=frosted
--xh-_material-border
--xh-select-content-fgcontentcolornot([data-xh-action-control])
xh-material=frosted
--xh-_material-fg
--xh-select-content-highlightcontentbackgroundnot([data-xh-action-control])
xh-material=frosted
--xh-_material-highlight
--xh-select-content-max-hcontentmax-block-sizedefault--xh-overlay-menu-max-h
--xh-select-content-max-wcontentmax-inline-sizedefaultnone
--xh-select-content-min-wcontentinline-sizedefault--xh-overlay-menu-min-w
--xh-select-content-pxcontentpadding-inlinedefault--xh-space-1
--xh-select-content-pycontentpadding-blockdefault--xh-space-1
--xh-select-content-radiuscontentborder-radiusdefault--xh-shape-overlay
--xh-select-content-shadowcontentbox-shadownot([data-xh-action-control])
xh-material=frosted
--xh-_material-shadow
--xh-select-control-bgcontrolbackground-colorxh-field-chrome--xh-_field-variant-bg-rest
--xh-select-control-bg-disabledcontrolbackground-colordisabled
xh-field-chrome
--xh-_field-variant-bg-disabled
--xh-select-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-select-control-bg-readonlycontrolbackground-colorreadonly
xh-field-chrome
--xh-_field-variant-bg-read-only
--xh-select-control-bordercontrolborderxh-field-chrome--xh-_field-variant-border-rest
--xh-select-control-border-focuscontrolborder-color
box-shadow
disabled
focus-within
not([data-disabled])
xh-field-chrome
--xh-_field-variant-border-focus
--xh-select-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-select-control-border-invalidcontrolborder-colorinvalid
xh-field-chrome
--xh-_field-variant-border-invalid
--xh-select-control-fgcontrolcolorxh-field-chrome--xh-fg-default
--xh-select-control-gapcontrolgapxh-field-chrome--xh-_select-gap
--xh-select-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-_select-h
--xh-select-control-min-wcontrol
root
min-inline-sizedefault
xh-field-chrome
--xh-control-min-w
--xh-select-control-pxcontrolpadding-inlinexh-field-chrome--xh-_select-px
--xh-select-control-radiuscontrolborder-radiusxh-field-chrome--xh-shape-control
--xh-select-control-shadowcontrolbox-shadowxh-field-chromenone
--xh-select-control-wrootinline-size
min-inline-size
default--xh-control-w
--xh-select-empty-fgemptycolordefault--xh-material-frosted-fg-muted
--xh-select-empty-font-sizeemptyfont-sizedefault--xh-_select-font-size
--xh-select-empty-pxemptypadding-inlinedefault--xh-_select-item-px
--xh-select-empty-pyemptypadding-blockdefault--xh-space-3
--xh-select-error-fgerrorcolordefault--xh-material-frosted-fg-muted
--xh-select-error-font-sizeerrorfont-sizedefault--xh-_select-font-size
--xh-select-error-pxerrorpadding-inlinedefault--xh-_select-item-px
--xh-select-error-pyerrorpadding-blockdefault--xh-space-3
--xh-select-footer-borderfooterborder-block-startdefault--xh-material-frosted-separator
--xh-select-footer-fgfootercolordefault--xh-material-frosted-fg-muted
--xh-select-footer-font-sizefooterfont-sizedefault--xh-text-secondary-size
--xh-select-footer-gapfootergapdefault--xh-space-2
--xh-select-footer-pxfooterpadding-inlinedefault--xh-space-2
--xh-select-footer-pyfooterpadding-blockdefault--xh-space-2
--xh-select-gaplabel
root
gap
margin-block-end
default--xh-space-1
--xh-select-group-gapgroupgapdefault--xh-list-option-gap
--xh-select-group-label-fggroup-labelcolordefault--xh-material-frosted-fg-muted
--xh-select-group-label-font-sizegroup-labelfont-sizedefault--xh-text-caption-size
--xh-select-group-label-font-weightgroup-labelfont-weightdefault--xh-font-weight-medium
--xh-select-group-label-pxgroup-labelpadding-inlinedefault--xh-_select-item-px
--xh-select-group-label-pygroup-labelpadding-blockdefault--xh-space-1
--xh-select-group-separator-colorgroupborder-block-startdefault--xh-material-frosted-separator
--xh-select-group-spacinggrouppadding-block-startdefault--xh-space-1_5
--xh-select-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-select-indicator-fgindicatorcolordefault--xh-fg-muted
--xh-select-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-select-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-select-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-_select-accent
--xh-select-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-select-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-select-item-fg
--xh-select-item-font-sizeitemfont-sizedefault--xh-_select-font-size
--xh-select-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-select-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-_select-gap
--xh-select-item-hitemmin-block-sizedefault--xh-_select-item-h
--xh-select-item-indicator-sizeitem-indicator--xh-icon-size
block-size
inline-size
default--xh-control-indicator-size
--xh-select-item-leadingitemline-heightdefault--xh-leading-normal
--xh-select-item-pxitempadding-inlinedefault--xh-_select-item-px
--xh-select-item-pyitempadding-blockdefault--xh-_select-item-py
--xh-select-item-radiusitemborder-radiusdefault--xh-shape-inset
--xh-select-label-fglabelcolordefault--xh-fg-muted
--xh-select-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-select-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-select-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-select-label-gaplabelmargin-block-enddefault--xh-space-2
--xh-select-layerpositionerz-indexdefault--xh-_layer
--xh-select-list-gaplistgapdefault--xh-list-option-gap
--xh-select-loading-fgloadingcolordefault--xh-material-frosted-fg-muted
--xh-select-loading-font-sizeloadingfont-sizedefault--xh-_select-font-size
--xh-select-loading-pxloadingpadding-inlinedefault--xh-_select-item-px
--xh-select-loading-pyloadingpadding-blockdefault--xh-space-3
--xh-select-placeholder-fgvalue-textcolorplaceholder--xh-fg-subtle
--xh-select-tag-list-gaptag-listgapxh-tag-list--xh-space-1
--xh-select-trigger-fgtriggercolordefault--xh-fg-default
--xh-select-trigger-font-sizetriggerfont-sizedefault--xh-_select-font-size
--xh-select-trigger-gaptriggergapdefault--xh-_select-gap

Released under The MIT License