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

查看生态总览
Skip to content

Scrollbar ​

General 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="scrollbar": root · track · thumb · corner

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-scrollbar>
Vue componentsXhScrollbarCorner XhScrollbarRoot XhScrollbarThumb XhScrollbarTrack
ComposableuseScrollbar
State machinescrollbarMachine
Skin@xihan-ui/styles/scrollbar.css

Props ​

PropTypeRequired
orientationOrientation
typeScrollbarType
hideDelaynumber
minThumbSizenumber
stepnumber
sizeSize
anchorScrollbarAnchor
disabledboolean
focusableboolean
controlsstring
gutterboolean
forceVisibleboolean
dirDirection
translationsPartial<ScrollbarTranslations>
onScrollStart(details: ScrollbarScrollDetails) => void
onScrollEnd(details: ScrollbarScrollDetails) => void
onDragStart(details: ScrollbarScrollDetails) => void
onDragEnd(details: ScrollbarScrollDetails) => void
onScrollChange(details: ScrollbarScrollDetails) => void
onReachEnd(details: ScrollbarScrollDetails) => void

Events ​

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

EventPayload
nameCustomEvent
scroll-start``
scroll-end``
drag-start``
drag-end``

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhScrollbarRootdefaultScrollbarRootSlotProps

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
XhScrollbarRootscrollableScrollbarTarget
XhScrollbarRootchildrenSlotChildren<ScrollbarRootSlotProps>

State ​

Public state is written to data-state.

PartValues
root'visible' | 'hidden'
corner'visible' | 'hidden'

The following names are internal to the state machine.

States: hidden · visible · hiding · dragging

Events: MEASURE · SCROLL · SCROLL.IDLE · POINTER.ENTER · POINTER.LEAVE · DRAG.START · DRAG.MOVE · DRAG.END · TRACK.CLICK · STEP · SCROLL.TO · after.hideDelay

Guards: showsOnHover · showsOnScroll · staysVisible · canInteract

connect API ​

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

MemberType
orientationOrientation
typeScrollbarType
overflowboolean
visibleboolean
nativeboolean
hoverboolean
draggingboolean
scrollingboolean
thumbSizenumber
thumbOffsetnumber
scrollnumber
maxnumber
scrollTo(offset: number) => void
scrollBy(delta: number) => void
measure() => void
getRootProps() => T['element']
getTrackProps() => T['element']
getThumbProps() => T['element']
getCornerProps() => 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
ArrowUp / ArrowLeftscrollbar.kbd.back
ArrowDown / ArrowRightscrollbar.kbd.forward
PageUpscrollbar.kbd.page-back
PageDownscrollbar.kbd.page-forward
Homescrollbar.kbd.start
Endscrollbar.kbd.end
Tab / Shift+Tabscrollbar.kbd.tab

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-hiddenundefined | 'true'
thumbaria-controlsprops.controls | undefined
thumbaria-disabled'true' | undefined
thumbaria-labeltranslations.thumb | undefined
thumbaria-orientationprops.orientation | undefined
thumbaria-valuemaxMath.round(max) | undefined
thumbaria-valuemin0 | undefined
thumbaria-valuenowMath.round(metrics.scroll) | undefined
thumbrole'scrollbar' | undefined

Style reference ​

Skin ​

@xihan-ui/styles/scrollbar.css is written against [data-scope="scrollbar"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-scrollbar 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-anchor'layer' | undefined
rootdata-disabled'' (present only while the condition holds)
rootdata-dragging'' (present only while the condition holds)
rootdata-gutter'' (present only while the condition holds)
rootdata-native'' (present only while the condition holds)
rootdata-orientationprops.orientation
rootdata-reveal-modeprops.type
rootdata-scrolling'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-state'visible' | 'hidden'
trackdata-disabled'' (present only while the condition holds)
trackdata-orientationprops.orientation
thumbdata-disabled'' (present only while the condition holds)
thumbdata-dragging'' (present only while the condition holds)
thumbdata-orientationprops.orientation
cornerdata-orientationprops.orientation
cornerdata-sizeprops.size
cornerdata-state'visible' | 'hidden'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-scrollbar-corner-bgcornerbackgrounddefault--xh-scrollbar-track-bg
--xh-scrollbar-thumb-bgthumbbackgrounddefault--xh-fg-scrollbar-thumb
--xh-scrollbar-thumb-bg-activethumbbackgrounddragging--xh-fg-scrollbar-thumb-active
--xh-scrollbar-thumb-bg-disabledthumbbackgrounddisabled--xh-border-subtle
--xh-scrollbar-thumb-bg-hoverthumbbackgroundhover--xh-fg-scrollbar-thumb-hover
--xh-scrollbar-thumb-radiusthumbborder-radiusdefault--xh-shape-pill
--xh-scrollbar-track-bgcorner
track
backgrounddefault--xh-bg-scrollbar-track
transparent

Released under The MIT License