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

查看生态总览
Skip to content

NavigationMenu ​

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="navigation-menu": root · list · item · trigger · trigger-indicator · content · branch-trigger · branch-indicator · branch-content · link · indicator · viewport

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-navigation-menu>
Vue componentsXhNavigationMenuBranchContent XhNavigationMenuBranchIndicator XhNavigationMenuBranchTrigger XhNavigationMenuContent XhNavigationMenuIndicator XhNavigationMenuItem XhNavigationMenuLink XhNavigationMenuList XhNavigationMenuRoot XhNavigationMenuTrigger XhNavigationMenuTriggerIndicator XhNavigationMenuViewport
ComposableuseNavigationMenu
State machinenavigationMenuMachine
Skin@xihan-ui/styles/navigation-menu.css

Props ​

PropTypeRequired
collectionNavigationMenuNode[]
valuestring | null
defaultValuestring | null
orientationOrientation
delayDurationnumber
skipDelayDurationnumber
dirDirection
loopboolean
disabledboolean
translationsPartial<NavigationMenuTranslations>
toneTone
sizeSize
onValueChange(details: NavigationMenuValueChangeDetails) => void

Elements of collection.

FieldTypeRequired
valuestringYes
labelstring
disabledboolean
hrefstring
currentboolean
childrenNavigationMenuNode[]

Events ​

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

EventPayload
value-changeNavigationMenuValueChangeDetails

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
XhNavigationMenuBranchContentvaluestringYes
XhNavigationMenuBranchIndicatorvaluestringYes
XhNavigationMenuBranchTriggervaluestringYes
XhNavigationMenuBranchTriggerdisabledboolean
XhNavigationMenuContentvaluestringYes
XhNavigationMenuLinkcurrentboolean
XhNavigationMenuRootrenderPanel(node: NavigationMenuNodeMeta) => ReactNode
XhNavigationMenuRootchildrenReactNode
XhNavigationMenuTriggervaluestringYes
XhNavigationMenuTriggerdisabledboolean
XhNavigationMenuTriggerIndicatorvaluestringYes
XhNavigationMenuTriggerIndicatordisabledboolean

State ​

Public state is written to data-state.

PartValues
root'open' | 'closed'
trigger'open' | 'closed'
trigger-indicator'open' | 'closed'
content'open' | 'closed'
branch-trigger'open' | 'closed'
branch-indicator'open' | 'closed'
branch-content'open' | 'closed'
indicator'open' | 'closed'
viewport'open' | 'closed'

The following names are internal to the state machine.

States: idle · opening · skipping

Events: TRIGGER.POINTER · TRIGGER.FOCUS · TRIGGER.TOGGLE · DISMISS · VALUE.SET · PRESENCE.SET · after.delayDuration · after.skipDelayDuration · PRESS.START · PRESS.END · BRANCH.TOGGLE · BRANCH.DISMISS

Guards: hasValue · isCurrent · shouldKeepOpen · canPress

connect API ​

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

MemberType
valuestring | null
collectionreadonly NavigationMenuNodeMeta[]
openboolean
isOpen(value: string) => boolean
branchValuestring | null
isBranchOpen(value: string) => boolean
setValue(next: string | null) => void
getRootProps() => T['element']
getListProps() => T['element']
getItemProps() => T['element']
getTriggerProps(props: NavigationMenuTriggerProps) => T['button']
getTriggerIndicatorProps(props: NavigationMenuTriggerProps) => T['element']
getContentProps(props: NavigationMenuContentProps) => T['element']
getBranchTriggerProps(props: NavigationMenuTriggerProps) => T['button']
getBranchIndicatorProps(props: NavigationMenuContentProps) => T['element']
getBranchContentProps(props: NavigationMenuContentProps) => T['element']
getLinkProps(props: NavigationMenuLinkProps) => T['element']
getIndicatorProps() => T['element']
getViewportProps() => 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 / Spacenavigation-menu.kbd.press
ArrowRight / ArrowDownnavigation-menu.kbd.next
ArrowLeft / ArrowUpnavigation-menu.kbd.prev
Homenavigation-menu.kbd.first
Endnavigation-menu.kbd.last
Enter / Spacenavigation-menu.kbd.toggle
Enter / Spacenavigation-menu.kbd.branch-toggle
Escapenavigation-menu.kbd.branch-escape
Escapenavigation-menu.kbd.escape
Tab / Shift+Tabnavigation-menu.kbd.tab

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-labelresolveTranslations(NAVIGATION_MENU_EN_US, prop('tran…
triggeraria-controlsid of the content part
triggeraria-disabled'true' | 'false'
triggeraria-expanded'true' | 'false'
trigger-indicatoraria-hidden'true'
contentaria-hidden!isOpen || undefined
contentaria-labelledbyid of the trigger part
contentrole'group'
branch-triggeraria-controlsid of the branch-content part
branch-triggeraria-disabled'true' | 'false'
branch-triggeraria-expanded'true' | 'false'
branch-indicatoraria-hidden'true'
branch-contentaria-labelledbyid of the branch-trigger part
branch-contentrole'group'
linkaria-current'page' | undefined
indicatoraria-hidden'true'
viewportaria-hidden!open || undefined

Style reference ​

Skin ​

@xihan-ui/styles/navigation-menu.css is written against [data-scope="navigation-menu"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-navigation-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
rootdata-orientationprops.orientation
rootdata-sizeprops.size
rootdata-state'open' | 'closed'
rootdata-toneprops.tone
listdata-orientationprops.orientation
triggerdata-disabled'' (present only while the condition holds)
triggerdata-in-path'' (present only while the condition holds)
triggerdata-orientationprops.orientation
triggerdata-pressed'' (present only while the condition holds)
triggerdata-state'open' | 'closed'
triggerdata-xh-collection-context'nav'
triggerdata-xh-collection-item''
triggerdata-xh-collection-sizeprops.size
trigger-indicatordata-disabled'' (present only while the condition holds)
trigger-indicatordata-orientationprops.orientation
trigger-indicatordata-state'open' | 'closed'
contentdata-instant'' (present only while the condition holds)
contentdata-orientationprops.orientation
contentdata-state'open' | 'closed'
branch-triggerdata-disabled'' (present only while the condition holds)
branch-triggerdata-pressed'' (present only while the condition holds)
branch-triggerdata-state'open' | 'closed'
branch-triggerdata-xh-collection-context'nav'
branch-triggerdata-xh-collection-item''
branch-triggerdata-xh-collection-sizeprops.size
branch-indicatordata-state'open' | 'closed'
branch-contentdata-state'open' | 'closed'
linkdata-current'' (present only while the condition holds)
linkdata-pressed'' (present only while the condition holds)
linkdata-xh-collection-context'nav'
linkdata-xh-collection-item''
linkdata-xh-collection-sizeprops.size
indicatordata-instant'' (present only while the condition holds)
indicatordata-orientationprops.orientation
indicatordata-state'open' | 'closed'
indicatordata-valuecontext.get('value')
viewportdata-instant'' (present only while the condition holds)
viewportdata-orientationprops.orientation
viewportdata-state'open' | 'closed'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-navigation-menu-branch-content-indentbranch-contentpadding-inline-startdefault--xh-space-4
--xh-navigation-menu-branch-indicator-sizebranch-indicator--xh-icon-size
block-size
inline-size
default--xh-control-indicator-size
--xh-navigation-menu-branch-trigger-gapbranch-triggergapdefault--xh-_navigation-menu-trigger-gap
--xh-navigation-menu-content-bgcontent
viewport
backgrounddefault--xh-bg-surface
--xh-navigation-menu-content-bordercontent
viewport
borderdefault--xh-border-default
--xh-navigation-menu-content-gapbranch-content
content
gapdefault--xh-space-1
--xh-navigation-menu-content-max-wcontent
viewport
max-inline-sizedefault--xh-overlay-max-w-xl
--xh-navigation-menu-content-min-wcontentmin-inline-sizedefault--xh-overlay-menu-min-w
--xh-navigation-menu-content-offsetcontent
viewport
inset-block-start
inset-inline-start
default
orientation=vertical
--xh-space-1
--xh-navigation-menu-content-pcontentpaddingdefault--xh-surface-pad-xs
--xh-navigation-menu-content-radiuscontent
viewport
border-radiusdefault--xh-shape-overlay
--xh-navigation-menu-content-shadowcontent
viewport
box-shadowdefault--xh-elevation-floating
--xh-navigation-menu-fgrootcolordefault--xh-fg-default
--xh-navigation-menu-font-sizeroot
trigger
font-sizedefault--xh-_navigation-menu-font-size
--xh-navigation-menu-gaplistgapdefault--xh-space-1
--xh-navigation-menu-icon-sizeroot--xh-icon-sizedefault
size=lg
size=sm
--xh-glyph-size-lg
--xh-glyph-size-md
--xh-glyph-size-sm
--xh-navigation-menu-indicator-colorindicator
link
backgroundcurrent
default
--xh-_navigation-menu-accent
--xh-navigation-menu-indicator-radiusindicator
link
border-radiuscurrent
default
--xh-shape-pill
--xh-navigation-menu-indicator-thicknessindicator
item
link
list
block-size
inline-size
inset-block-end
current
default
orientation=horizontal
orientation=vertical
--xh-stroke-thick
--xh-navigation-menu-layercontent
viewport
z-indexdefault--xh-_layer
--xh-navigation-menu-link-bg-hoverbranch-trigger
link
background-colordisabled
error
highlighted
hover
is(:focus-visible, [data-highlighted])
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
xh-collection-context=nav
--xh-_navigation-menu-highlight-bg
--xh-navigation-menu-link-bg-pressedbranch-trigger
link
background-colordisabled
error
is(:active, [data-pressed])
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
pressed
xh-collection-context=nav
--xh-bg-subtle-hover
--xh-navigation-menu-link-fgbranch-trigger
link
colordefault
disabled
error
highlighted
hover
is(:active, [data-pressed])
is(:focus-visible, [data-highlighted])
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
pressed
xh-collection-context=nav
--xh-fg-default
--xh-navigation-menu-link-fg-currentlinkcolorcurrent
disabled
error
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
xh-collection-context=nav
--xh-fg-brand
--xh-navigation-menu-link-font-sizebranch-trigger
link
font-sizedefault--xh-_navigation-menu-link-font-size
--xh-navigation-menu-link-font-weight-currentlinkfont-weightcurrent
disabled
error
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
xh-collection-context=nav
--xh-font-weight-medium
--xh-navigation-menu-link-pxbranch-trigger
link
padding-inlinedefault--xh-_navigation-menu-link-px
--xh-navigation-menu-link-pybranch-trigger
link
padding-blockdefault--xh-_navigation-menu-link-py
--xh-navigation-menu-link-radiusbranch-trigger
link
border-radiusdefault--xh-shape-control
--xh-navigation-menu-trigger-bg-activetriggerbackground-colorin-path
xh-collection-context=nav
--xh-_navigation-menu-highlight-bg
--xh-navigation-menu-trigger-bg-hovertriggerbackground-colordisabled
error
hover
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
xh-collection-context=nav
--xh-_navigation-menu-highlight-bg
--xh-navigation-menu-trigger-bg-pressedtriggerbackground-colordisabled
error
is(:active, [data-pressed])
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
pressed
xh-collection-context=nav
--xh-bg-subtle-hover
--xh-navigation-menu-trigger-fgtriggercolordefault
xh-collection-context=nav
--xh-fg-muted
--xh-navigation-menu-trigger-font-weighttriggerfont-weightdefault
xh-collection-context=nav
--xh-font-weight-regular
--xh-navigation-menu-trigger-gaptriggergapdefault--xh-_navigation-menu-trigger-gap
--xh-navigation-menu-trigger-htriggerblock-sizedefault--xh-_navigation-menu-trigger-h
--xh-navigation-menu-trigger-pxtriggerpadding-inlinedefault--xh-_navigation-menu-trigger-px
--xh-navigation-menu-trigger-radiustriggerborder-radiusdefault--xh-shape-control
--xh-navigation-menu-viewport-pviewportpaddingdefault--xh-space-2

Released under The MIT License