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

查看生态总览
Skip to content

Anchor ​

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="anchor": root · list · item · link · link-text · indicator

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-anchor>
Vue componentsXhAnchorIndicator XhAnchorItem XhAnchorLink XhAnchorLinkText XhAnchorList XhAnchorRoot
ComposableuseAnchor
State machineanchorMachine
Skin@xihan-ui/styles/anchor.css

Props ​

PropTypeRequired
valuestring | null
defaultValuestring | null
collectionreadonly string[]
offsetnumber
boundsnumber
smoothboolean
dirDirection
orientationOrientation
translationsPartial<AnchorTranslations>
toneTone
sizeSize
onValueChange(details: AnchorValueChangeDetails) => void

Events ​

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

EventPayload
value-changeAnchorValueChangeDetails

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
XhAnchorLinkvaluestringYes
XhAnchorRoottarget() => HTMLElement | null
XhAnchorRootchildrenReactNode

State ​

The following names are internal to the state machine.

States: idle · scrolling

Events: SPY.RESOLVE · LINK.CLICK · VALUE.SET · SCROLL.SETTLE · PRESS.START · PRESS.END

Guards: isSmooth · isTargetReached · canPress

connect API ​

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

MemberType
valuestring | null
isActive(value: string) => boolean
setValue(next: string | null) => void
getRootProps() => T['element']
getListProps() => T['element']
getItemProps() => T['element']
getLinkProps(props: AnchorLinkProps) => T['element']
getLinkTextProps() => T['element']
getIndicatorProps() => 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
Enteranchor.kbd.link
Enter / Spaceanchor.kbd.press
Tab / Shift+Tabanchor.kbd.tab

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-labelresolveTranslations(ANCHOR_EN_US, prop('translations'…
linkaria-current'location' | undefined
indicatoraria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/anchor.css is written against [data-scope="anchor"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-anchor 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-toneprops.tone
listdata-orientationprops.orientation
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
link-textdata-xh-collection-slot'text'
indicatordata-instant'' (present only while the condition holds)
indicatordata-orientationprops.orientation
indicatordata-valuecontext.get('value')

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-anchor-fglink
root
colordefault
xh-collection-context=nav
--xh-fg-muted
--xh-anchor-font-sizelink
root
font-sizedefault--xh-_anchor-font-size
--xh-anchor-gaplistgapdefault--xh-space-1
--xh-anchor-gap-horizontallistgaporientation=horizontal--xh-space-2
--xh-anchor-indicator-colorindicator
link
backgroundcurrent
default
--xh-_anchor-accent
--xh-anchor-indicator-radiusindicator
link
border-radiuscurrent
default
--xh-shape-pill
--xh-anchor-indicator-thicknessindicator
link
list
block-size
inline-size
inset-block-end
inset-inline-start
current
default
orientation=horizontal
orientation=vertical
--xh-stroke-thick
--xh-anchor-leadinglink
root
line-heightdefault--xh-leading-normal
--xh-anchor-link-bg-hoverlinkbackground-colordisabled
error
hover
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
xh-collection-context=nav
--xh-bg-subtle
--xh-anchor-link-bg-pressedlinkbackground-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-anchor-link-fg-currentlinkcolorcurrent
disabled
error
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
xh-collection-context=nav
--xh-_anchor-accent-text
--xh-anchor-link-fg-hoverlinkcolordisabled
error
hover
not([aria-disabled='true'], [data-disabled], [aria-busy='true'], [data-error])
xh-collection-context=nav
--xh-fg-default
--xh-anchor-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-anchor-link-max-wlinkmax-inline-sizedefault--xh-nav-link-max-w
--xh-anchor-link-pxlinkpadding-inlinedefault--xh-_anchor-link-px
--xh-anchor-link-pylinkpadding-blockdefault--xh-space-1
--xh-anchor-link-radiuslinkborder-radiusdefault--xh-shape-control
--xh-anchor-tracklistborder-block-end
border-inline-start
default
orientation=horizontal
--xh-border-default

Released under The MIT License