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

查看生态总览
Skip to content

ContextMenu ​

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="context-menu": root · 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-context-menu>
Vue componentsXhContextMenuArrow XhContextMenuCheckboxItem XhContextMenuContent XhContextMenuGroup XhContextMenuGroupLabel XhContextMenuItem XhContextMenuItemDescription XhContextMenuItemIcon XhContextMenuItemIndicator XhContextMenuItemShortcut XhContextMenuItemSuffix XhContextMenuItemText XhContextMenuPositioner XhContextMenuRadioGroup XhContextMenuRadioItem XhContextMenuRoot XhContextMenuSeparator XhContextMenuSub XhContextMenuSubTrigger XhContextMenuTrigger
ComposableuseContextMenu
State machinecontextMenuMachine
Skin@xihan-ui/styles/context-menu.css

Props ​

PropTypeRequired
collectionContextMenuNode[]
checkboxValuestring[]
defaultCheckboxValuestring[]
radioValueMenuRadioValue
defaultRadioValueMenuRadioValue
openboolean
defaultOpenboolean
placementPlacement
offsetnumber
loopboolean
dirDirection
typeaheadboolean
translationsPartial<ContextMenuTranslations>
longPressDelaynumber
disabledboolean
toneTone
sizeSize
onOpenChange(details: ContextMenuOpenChangeDetails) => void
onItemSelect(details: ContextMenuItemSelectDetails) => void
onCheckboxValueChange(details: MenuCheckboxValueChangeDetails) => void
onRadioValueChange(details: MenuRadioValueChangeDetails) => void

ContextMenuNode ​

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-changeContextMenuOpenChangeDetails
item-selectContextMenuItemSelectDetails
checkbox-value-changeContextMenuCheckboxValueChangeDetails
radio-value-changeContextMenuRadioValueChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhContextMenuRootdefaultContextMenuRootSlotProps
XhContextMenuRoottrigger—
XhContextMenuRootitemContextMenuNodeMeta
XhContextMenuRootitem-prefixContextMenuNodeMeta
XhContextMenuRootitem-suffixContextMenuNodeMeta
XhContextMenuSubdefaultContextMenuSubSlotProps

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
XhContextMenuGroupvaluestringYes
XhContextMenuItemvaluestringYes
XhContextMenuItemdisabledboolean
XhContextMenuPositionercontainer() => Element | null
XhContextMenuRadioGroupvaluestringYes
XhContextMenuRoottriggerReactNode
XhContextMenuRootrenderItem(node: ContextMenuNodeMeta) => ReactNode
XhContextMenuRootrenderItemPrefix(node: ContextMenuNodeMeta) => ReactNode
XhContextMenuRootrenderItemSuffix(node: ContextMenuNodeMeta) => ReactNode
XhContextMenuRootchildrenSlotChildren<ContextMenuRootSlotProps>
XhContextMenuSubvaluestringYes
XhContextMenuSublabelstring
XhContextMenuSubiconIconRecord
XhContextMenuSubdisabledboolean
XhContextMenuSubcollectionMenuNode[]
XhContextMenuSubcheckboxValuestring[]
XhContextMenuSubdefaultCheckboxValuestring[]
XhContextMenuSubradioValueContextMenuRadioValue
XhContextMenuSubdefaultRadioValueContextMenuRadioValue
XhContextMenuSubplacementPlacement
XhContextMenuSuboffsetnumber
XhContextMenuSubloopboolean
XhContextMenuSubopenOnHoverboolean
XhContextMenuSubhoverOpenDelaynumber
XhContextMenuSubhoverCloseDelaynumber
XhContextMenuSubdirDirection
XhContextMenuSubtoneTone
XhContextMenuSubsizeSize
XhContextMenuSubonCheckboxValueChangeMenuSchema['props']['onCheckboxValueChange']
XhContextMenuSubonRadioValueChangeMenuSchema['props']['onRadioValueChange']
XhContextMenuSubchildrenSlotChildren<ContextMenuSubSlotProps>

State ​

Public state is written to data-state.

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

The following names are internal to the state machine.

States: closed · pressing · open

Events: CONTEXT.MENU · OPEN · CLOSE · PRESS.START · PRESS.MOVE · PRESS.END · after.longPressDelay · ITEM.PRESS.START · ITEM.PRESS.END · CHECKBOX.VALUE.SET · RADIO.VALUE.SET · CONTROLLED.OPEN · CONTROLLED.CLOSE · ITEM.FOCUS · FOCUS.CLEAR · ITEM.LOST · ITEM.SELECT

Guards: isOpenControlled · movedBeyondTolerance · canPressItem · keepsMenuOpen · isDisabled

connect API ​

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

MemberType
openboolean
disabledboolean
collectionreadonly ContextMenuNodeMeta[]
pressingboolean
pointContextMenuPoint | null
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
openAt(x: number, y: number) => void
getRootProps() => T['element']
getTriggerProps() => T['element']
getPositionerProps() => T['element']
getContentProps() => T['element']
getItemProps(props: ContextMenuItemProps) => T['element']
getCheckboxItemProps(props: ContextMenuCheckboxItemProps) => T['element']
getRadioItemProps(props: ContextMenuRadioItemProps) => T['element']
getItemIconProps(props: ContextMenuAnyItemProps) => T['element']
getItemTextProps(props: ContextMenuAnyItemProps) => T['element']
getItemIndicatorProps(props: ContextMenuAnyItemProps) => T['element']
getItemDescriptionProps(props: ContextMenuAnyItemProps) => T['element']
getItemShortcutProps(props: ContextMenuAnyItemProps) => T['element']
getItemSuffixProps(props: ContextMenuAnyItemProps) => T['element']
getSeparatorProps() => T['element']
getGroupProps(props: ContextMenuGroupProps) => T['element']
getRadioGroupProps(props: ContextMenuGroupProps) => T['element']
getGroupLabelProps(props: ContextMenuGroupProps) => 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
ContextMenu / Shift+F10context-menu.kbd.open
ArrowDowncontext-menu.kbd.next
ArrowUpcontext-menu.kbd.prev
Homecontext-menu.kbd.first
Endcontext-menu.kbd.last
any single printable charactercontext-menu.kbd.typeahead
Enter / Spacecontext-menu.kbd.select
Enter / Spacecontext-menu.kbd.press
Escapecontext-menu.kbd.escape
Tab / Shift+Tabcontext-menu.kbd.tab

ARIA ​

These attributes are produced by connect.

PartAttributeValue
triggeraria-controlsundefined | id of the content part
triggeraria-haspopupundefined | 'menu'
triggeraria-keyshortcutsundefined | 'Shift+F10'
contentaria-hidden!open || undefined
contentaria-labeltranslations.content
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'
radio-grouparia-labelledbyid of the group-label part
radio-grouprole'group'

Style reference ​

Skin ​

@xihan-ui/styles/context-menu.css is written against [data-scope="context-menu"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-context-menu in place of data-scope (same specificity) and sits in the xihan.components and xihan.motion layers. 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-sizeprops.size
rootdata-state'open' | 'closed'
rootdata-toneprops.tone
triggerdata-disabled'' (present only while the condition holds)
triggerdata-pressing'' (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-sizeprops.size
positionerdata-state'open' | 'closed'
positionerdata-toneprops.tone
contentdata-instant'' (present only while the condition holds)
contentdata-placementactual placement computed by the positioning engine
contentdata-state'open' | 'closed'
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
radio-groupdata-valuegroup.value

CSS variables ​

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

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

Released under The MIT License