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

查看生态总览
Skip to content

Menu ​

Navigation 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="menu": trigger · positioner · content · item · item-icon · item-text · item-description · item-shortcut · item-suffix · item-indicator · separator · group · group-label · arrow

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-menu>
Vue componentsXhMenuArrow XhMenuCheckboxItem XhMenuContent XhMenuGroup XhMenuGroupLabel XhMenuItem XhMenuItemDescription XhMenuItemIcon XhMenuItemIndicator XhMenuItemShortcut XhMenuItemSuffix XhMenuItemText XhMenuPositioner XhMenuRadioGroup XhMenuRadioItem XhMenuRoot XhMenuSeparator XhMenuSub XhMenuSubTrigger XhMenuTrigger
ComposableuseMenu
State machinemenuMachine
Skin@xihan-ui/styles/menu.css

Props ​

PropTypeRequired
collectionMenuNode[]
checkboxValuestring[]
defaultCheckboxValuestring[]
radioValueMenuRadioValue
defaultRadioValueMenuRadioValue
openboolean
defaultOpenboolean
anchorHTMLElement | null
placementPlacement
offsetnumber
loopboolean
dirDirection
toneTone
sizeSize
fitAvailableHeightboolean
typeaheadboolean
disabledboolean
translationsPartial<MenuTranslations>
submenuboolean
openOnHoverboolean
hoverOpenDelaynumber
hoverCloseDelaynumber
onOpenChange(details: MenuOpenChangeDetails) => void
onItemSelect(details: MenuItemSelectDetails) => void
onCheckboxValueChange(details: MenuCheckboxValueChangeDetails) => void
onRadioValueChange(details: MenuRadioValueChangeDetails) => void

Elements of collection.

FieldTypeRequired
valuestringYes
kindMenuChoiceKind
labelstring
disabledboolean
toneTone
iconIconRecord
descriptionstring
shortcutstring
keyshortcutsstring
groupstring
groupLabelstring
separatorBeforeboolean
closeOnSelectboolean
childrenMenuNode[]
checkboxValuestring[]
radioValueMenuRadioValue

Events ​

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

EventPayload
open-changeMenuOpenChangeDetails
item-selectMenuItemSelectDetails
checkbox-value-changeMenuCheckboxValueChangeDetails
radio-value-changeMenuRadioValueChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhMenuRootdefaultMenuRootSlotProps
XhMenuRoottrigger—
XhMenuRootitemMenuNodeMeta
XhMenuRootitem-prefixMenuNodeMeta
XhMenuRootitem-suffixMenuNodeMeta
XhMenuSubdefaultMenuSubSlotProps

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
XhMenuGroupvaluestringYes
XhMenuItemvaluestringYes
XhMenuItemdisabledboolean
XhMenuPositionercontainer() => Element | null
XhMenuRadioGroupvaluestringYes
XhMenuRoottriggerReactNode
XhMenuRoottriggerAsChildboolean
XhMenuRootlabelstring
XhMenuRootrenderItem(node: MenuNodeMeta) => ReactNode
XhMenuRootrenderItemPrefix(node: MenuNodeMeta) => ReactNode
XhMenuRootrenderItemSuffix(node: MenuNodeMeta) => ReactNode
XhMenuRootchildrenSlotChildren<MenuRootSlotProps>
XhMenuSubvaluestringYes
XhMenuSublabelstring
XhMenuSubiconIconRecord
XhMenuSubdisabledboolean
XhMenuSubcollectionMenuNode[]
XhMenuSubcheckboxValuestring[]
XhMenuSubdefaultCheckboxValuestring[]
XhMenuSubradioValueMenuRadioValue
XhMenuSubdefaultRadioValueMenuRadioValue
XhMenuSubplacementPlacement
XhMenuSuboffsetnumber
XhMenuSubloopboolean
XhMenuSubopenOnHoverboolean
XhMenuSubhoverOpenDelaynumber
XhMenuSubhoverCloseDelaynumber
XhMenuSubdirDirection
XhMenuSubtoneTone
XhMenuSubsizeSize
XhMenuSubfitAvailableHeightboolean
XhMenuSubonCheckboxValueChangeMenuProps['onCheckboxValueChange']
XhMenuSubonRadioValueChangeMenuProps['onRadioValueChange']
XhMenuSubchildrenSlotChildren<MenuSubSlotProps>

State ​

Public state is written to data-state.

PartValues
trigger'open' | 'closed'
positioner'open' | 'closed'
content'open' | 'closed'
item-indicator'checked' | 'unchecked' | 'checked' | 'unchecked' | undefined
submenu-trigger'open' | 'closed'

The following names are internal to the state machine.

States: open · closed

Events: OPEN · TOGGLE · CLOSE · PRESS.START · PRESS.END · CHECKBOX.VALUE.SET · RADIO.VALUE.SET · CONTROLLED.OPEN · CONTROLLED.CLOSE · ITEM.FOCUS · FOCUS.CLEAR · ITEM.LOST · ITEM.SELECT

Guards: isOpenControlled · canPress · keepsMenuOpen

connect API ​

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

MemberType
openboolean
disabledboolean
collectionreadonly MenuNodeMeta[]
focusedValuestring | null
checkboxValuereadonly string[]
radioValueReadonly<MenuRadioValue>
isCheckboxItemChecked(value: string) => boolean
isRadioItemChecked(group: string, value: string) => boolean
setCheckboxValue(next: string[]) => void
setRadioValue(next: MenuRadioValue) => void
setOpen(next: boolean) => void
getTriggerProps() => T['button']
getPositionerProps() => T['element']
getContentProps() => T['element']
getItemProps(props: MenuItemProps) => T['element']
getCheckboxItemProps(props: MenuCheckboxItemProps) => T['element']
getRadioItemProps(props: MenuRadioItemProps) => T['element']
getItemIconProps(props: MenuAnyItemProps) => T['element']
getItemTextProps(props: MenuAnyItemProps) => T['element']
getItemIndicatorProps(props: MenuAnyItemProps) => T['element']
getItemDescriptionProps(props: MenuAnyItemProps) => T['element']
getItemShortcutProps(props: MenuAnyItemProps) => T['element']
getItemSuffixProps(props: MenuAnyItemProps) => T['element']
getSubmenuTriggerProps(props: MenuItemProps) => T['element']
getSeparatorProps() => T['element']
getGroupProps(props: MenuGroupProps) => T['element']
getRadioGroupProps(props: MenuGroupProps) => T['element']
getGroupLabelProps(props: MenuGroupProps) => T['element']
getArrowProps() => 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 / Space / ArrowDownmenu.kbd.open-first
ArrowUpmenu.kbd.open-last
ArrowDownmenu.kbd.next
ArrowUpmenu.kbd.prev
Homemenu.kbd.first
Endmenu.kbd.last
Enter / Spacemenu.kbd.select
Enter / Spacemenu.kbd.press
Escapemenu.kbd.escape
Tab / Shift+Tabmenu.kbd.tab

ARIA ​

These attributes are produced by connect.

PartAttributeValue
triggeraria-controlsid of the content part
triggeraria-expanded'true' | 'false'
triggeraria-haspopup'menu'
triggeraria-labelprops.translations.trigger
contentaria-hidden!open || undefined
contentaria-labelprops.translations.content
contentaria-labelledbyid of the trigger part | undefined
contentrole'menu'
item-iconaria-hidden'true'
item-shortcutaria-hidden'true'
item-indicatoraria-hidden'true'
separatoraria-orientation'horizontal'
separatorrole'separator'
grouparia-labelledbyid of the group-label part
grouprole'group'
arrowaria-hidden'true'
submenu-triggeraria-controlsid of the content part
submenu-triggeraria-disabled'true' | 'false'
submenu-triggeraria-expanded'true' | 'false'
submenu-triggeraria-haspopup'menu'
radio-grouparia-labelledbyid of the group-label part
submenu-triggerrole'menuitem'
radio-grouprole'group'

Style reference ​

Skin ​

@xihan-ui/styles/menu.css is written against [data-scope="menu"][data-part="trigger"] part selectors; the published build uses the mount class .xh-scope-menu 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-disabled'' (present only while the condition holds)
triggerdata-state'open' | 'closed'
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-state'open' | 'closed'
contentdata-fit-available-height'' (present only while the condition holds)
contentdata-instant'' (present only while the condition holds)
contentdata-placementactual placement computed by the positioning engine
contentdata-sizeprops.size
contentdata-state'open' | 'closed'
contentdata-toneprops.tone
contentdata-xh-material'frosted'
itemdata-xh-collection-context'overlay'
itemdata-xh-collection-item''
item-icondata-disabled'' (present only while the condition holds)
item-icondata-highlighted'' (present only while the condition holds)
item-icondata-xh-collection-slot'icon'
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'
item-indicatordata-disabled'' (present only while the condition holds)
item-indicatordata-highlighted'' (present only while the condition holds)
item-indicatordata-state'checked' | 'unchecked' | 'checked' | 'unchecked' | undefined
item-indicatordata-xh-collection-slot'indicator'
item-indicatordata-xh-menu-choice-indicatoritem.kind | undefined
separatordata-xh-collection-separator''
arrowdata-placementactual placement computed by the positioning engine
submenu-triggerdata-disabled'' (present only while the condition holds)
submenu-triggerdata-in-path'' (present only while the condition holds)
submenu-triggerdata-pressed'' (present only while the condition holds)
submenu-triggerdata-state'open' | 'closed'
radio-groupdata-valuegroup.value
submenu-triggerdata-xh-collection-context'overlay'
submenu-triggerdata-xh-collection-item''
submenu-triggerdata-xh-collection-sizeprops.size

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-menu-arrow-sizearrow--xh-_overlay-arrow-sizedefault--xh-overlay-arrow-size
--xh-menu-backdropcontent-webkit-backdrop-filter
backdrop-filter
xh-material=frosted--xh-_material-backdrop
--xh-menu-borderarrow
content
borderdefault
not([data-xh-action-control])
xh-material=frosted
--xh-_material-border
--xh-material-frosted-border
--xh-menu-content-bgarrow
content
backgrounddefault
not([data-xh-action-control])
xh-material=frosted
--xh-_material-bg
--xh-material-frosted-bg
--xh-menu-content-fgcontentcolornot([data-xh-action-control])
xh-material=frosted
--xh-_material-fg
--xh-menu-content-gapcontentgapdefault--xh-list-option-gap
--xh-menu-content-pxcontentpadding-inlinedefault--xh-space-1
--xh-menu-content-pycontentpadding-blockdefault--xh-surface-pad-xs
--xh-menu-content-radiuscontentborder-radiusdefault--xh-shape-overlay
--xh-menu-content-shadowcontentbox-shadownot([data-xh-action-control])
xh-material=frosted
--xh-_material-shadow
--xh-menu-group-gapgroupgapdefault--xh-list-option-gap
--xh-menu-group-label-fggroup-labelcolordefault--xh-material-frosted-fg-muted
--xh-menu-group-label-font-sizegroup-labelfont-sizedefault--xh-text-caption-size
--xh-menu-group-label-font-weightgroup-labelfont-weightdefault--xh-font-weight-regular
--xh-menu-group-label-mtgroup-labelmargin-block-startdefault--xh-space-2
--xh-menu-group-label-pxgroup-labelpadding-inlinedefault--xh-_menu-item-px
--xh-menu-group-label-pygroup-labelpadding-blockdefault--xh-space-1
--xh-menu-highlightcontentbackgroundnot([data-xh-action-control])
xh-material=frosted
--xh-_material-highlight
--xh-menu-icon-sizecontent--xh-icon-sizedefault
size=lg
size=sm
--xh-glyph-size-lg
--xh-glyph-size-md
--xh-glyph-size-sm
--xh-menu-item-bg-activeitembackground-colorin-path--xh-bg-subtle
--xh-menu-item-bg-hoveritembackground-colordisabled
error
highlighted
hover
is(:focus-visible, [data-highlighted])
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
--xh-bg-subtle
--xh-menu-item-bg-presseditembackground-colordisabled
error
is(:active, [data-pressed])
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
pressed
--xh-bg-subtle-hover
--xh-menu-item-description-fgitem-descriptioncolordefault--xh-material-frosted-fg-muted
--xh-menu-item-description-font-sizeitem-descriptionfont-sizedefault--xh-control-caption-md
--xh-menu-item-fgitemcolordefault
disabled
error
highlighted
hover
in-path
is(:active, [data-pressed])
is(:focus-visible, [data-highlighted])
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
pressed
--xh-material-frosted-fg
--xh-menu-item-font-sizeitemfont-sizedefault--xh-_menu-font-size
--xh-menu-item-gapitemgapdefault--xh-_menu-item-gap
--xh-menu-item-hitemmin-block-sizedefault--xh-_menu-item-h
--xh-menu-item-indicator-fgitem-indicatorcolordefault--xh-_tone
--xh-menu-item-indicator-sizecontent
group
item
item-indicator
--xh-icon-size
block-size
inline-size
default
has(> [data-scope='menu'][data-part='item'] > [data-xh-menu-choice-indicator], > [data-scope='menu'][data-part='group'] > [data-scope='menu'][data-part='item'] > [data-xh-menu-choice-indicator])
not([aria-haspopup='menu'], [aria-checked])
xh-menu-choice-indicator
--xh-control-indicator-size
--xh-menu-item-leadingitemline-heightdefault--xh-leading-normal
--xh-menu-item-pxitempadding-inlinedefault--xh-_menu-item-px
--xh-menu-item-pyitempadding-blockdefault--xh-_menu-item-py
--xh-menu-item-radiusitemborder-radiusdefault--xh-shape-inset
--xh-menu-layerpositionerz-indexdefault--xh-_layer
--xh-menu-max-hcontentmax-block-sizedefault--xh-_menu-max-h
--xh-menu-max-wcontentmax-inline-sizedefault--xh-overlay-max-w
--xh-menu-min-wcontentmin-inline-sizedefault--xh-overlay-menu-min-w
--xh-menu-separator-colorseparatorbackgrounddefault--xh-material-frosted-separator
--xh-menu-separator-myseparatormargin-blockdefault--xh-space-0_5
--xh-menu-separator-radiusseparatorborder-radiusdefault--xh-shape-pill
--xh-menu-separator-thicknessseparatorblock-sizedefault--xh-stroke-thin
--xh-menu-submenu-indicator-fgitembackground-colordefaultcurrentColor
--xh-menu-submenu-indicator-sizeitemblock-size
inline-size
default--xh-control-indicator-size
--xh-menu-trigger-bg-activetriggerbackgrounddisabled
not([data-disabled])
state=open
--xh-bg-subtle

Released under The MIT License