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

查看生态总览
Skip to content

Slider ​

Data entry 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="slider": root · label · control · track · range · thumb · value-text · tick-group · tick · tick-label · hidden-input

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-slider>
Vue componentsXhSliderControl XhSliderHiddenInput XhSliderLabel XhSliderRange XhSliderRoot XhSliderThumb XhSliderTickGroup XhSliderTrack XhSliderValueText
ComposableuseSlider
State machinesliderMachine
Skin@xihan-ui/styles/slider.css

Props ​

PropTypeRequired
labelledboolean
ariaLabelstring
valuenumber[]
defaultValuenumber[]
minnumber
maxnumber
stepnumber
largeStepnumber
orientationOrientation
dirDirection
disabledboolean
readOnlyboolean
invalidboolean
requiredboolean
toneTone
sizeSize
namestring
minStepsBetweenThumbsnumber
marksSliderMark[]
snapToMarksboolean
invertedboolean
draggableRangeboolean
trackFillboolean
getValueText(details: SliderValueTextDetails) => string
onValueChange(details: SliderValueChangeDetails) => void
onValueChangeEnd(details: SliderValueChangeEndDetails) => void

SliderMark ​

Elements of marks.

FieldTypeRequired
valuenumberYes
labelstring

Events ​

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

EventPayload
value-changeSliderValueTextDetails
value-change-endSliderValueChangeEndDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhSliderRootdefaultSliderRootSlotProps
XhSliderRootlabel—
XhSliderTickGrouptickSliderTickGroupTickSlotProps

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
XhSliderRootlabelReactNode
XhSliderRootchildrenSlotChildren<SliderRootSlotProps>
XhSliderThumbindexnumber | string
XhSliderTickGrouptickSlotChildren<SliderTickSlotProps>

State ​

The following names are internal to the state machine.

States: idle · dragging

Events: VALUE.SET · THUMB.STEP · THUMB.TO_MIN · THUMB.TO_MAX · THUMB.SET · THUMB.FOCUS · DRAG.START · DRAG.MOVE · DRAG.END · FORM.RESET

Guards: canDrag

connect API ​

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

MemberType
valuenumber[]
range{ start: number, end: number }
thumbsSliderThumbState[]
marksSliderMarkMeta[]
draggingboolean
disabledboolean
readOnlyboolean
valueText(index: number) => string
setValue(next: number[]) => void
setThumbValue(index: number, next: number) => void
getRootProps() => T['element']
getLabelProps() => T['label']
getControlProps() => T['element']
getTrackProps() => T['element']
getRangeProps() => T['element']
getThumbProps(index: number) => T['element']
getValueTextProps(index: number) => T['element']
getTickGroupProps() => T['element']
getTickProps(props: SliderTickProps) => T['element']
getTickLabelProps(props: SliderTickProps) => T['element']
getHiddenInputProps(index: number) => T['input']

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
ArrowRight / ArrowUpslider.kbd.increment
ArrowLeft / ArrowDownslider.kbd.decrement
PageUpslider.kbd.large-increment
PageDownslider.kbd.large-decrement
Homeslider.kbd.min
Endslider.kbd.max

ARIA ​

These attributes are produced by connect.

PartAttributeValue
thumbaria-disabled'true' | 'false'
thumbaria-labelprops.ariaLabel
thumbaria-labelledbyid of the label part | undefined
thumbaria-orientationprops.orientation
thumbaria-valuemaxString(thumb.max)
thumbaria-valueminString(thumb.min)
thumbaria-valuenowString(thumb.value)
thumbaria-valuetextprop('getValueText')?.({ value: thumb.value, index: t…
thumbrole'slider'
value-textaria-hidden'true'
tickaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/slider.css is written against [data-scope="slider"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-slider 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-disabled'' (present only while the condition holds)
rootdata-dragging'' (present only while the condition holds)
rootdata-invalid'' (present only while the condition holds)
rootdata-orientationprops.orientation
rootdata-readonly'' (present only while the condition holds)
rootdata-required'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-toneprops.tone
labeldata-disabled'' (present only while the condition holds)
labeldata-dragging'' (present only while the condition holds)
labeldata-invalid'' (present only while the condition holds)
labeldata-orientationprops.orientation
labeldata-readonly'' (present only while the condition holds)
labeldata-required'' (present only while the condition holds)
controldata-disabled'' (present only while the condition holds)
controldata-dragging'' (present only while the condition holds)
controldata-invalid'' (present only while the condition holds)
controldata-orientationprops.orientation
controldata-readonly'' (present only while the condition holds)
trackdata-disabled'' (present only while the condition holds)
trackdata-dragging'' (present only while the condition holds)
trackdata-invalid'' (present only while the condition holds)
trackdata-orientationprops.orientation
trackdata-readonly'' (present only while the condition holds)
rangedata-disabled'' (present only while the condition holds)
rangedata-draggable'' (present only while the condition holds)
rangedata-dragging'' (present only while the condition holds)
rangedata-invalid'' (present only while the condition holds)
rangedata-orientationprops.orientation
rangedata-readonly'' (present only while the condition holds)
thumbdata-disabled'' (present only while the condition holds)
thumbdata-dragging'' (present only while the condition holds)
thumbdata-indexString(thumb.index)
thumbdata-invalid'' (present only while the condition holds)
thumbdata-orientationprops.orientation
thumbdata-readonly'' (present only while the condition holds)
value-textdata-disabled'' (present only while the condition holds)
value-textdata-dragging'' (present only while the condition holds)
value-textdata-indexString(thumb.index)
value-textdata-invalid'' (present only while the condition holds)
value-textdata-orientationprops.orientation
value-textdata-readonly'' (present only while the condition holds)
tick-groupdata-disabled'' (present only while the condition holds)
tick-groupdata-dragging'' (present only while the condition holds)
tick-groupdata-invalid'' (present only while the condition holds)
tick-groupdata-orientationprops.orientation
tick-groupdata-readonly'' (present only while the condition holds)
tickdata-passed'' (present only while the condition holds)
tick-labeldata-passed'' (present only while the condition holds)
hidden-inputdata-indexString(thumb.index)

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-slider-control-guttercontrol
root
margin-inlinehas([data-part='tick-label'])
orientation=horizontal
--xh-space-6
--xh-slider-gaplabel
root
gap
margin-block-end
default--xh-space-1
--xh-slider-label-fglabelcolordefault--xh-fg-muted
--xh-slider-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-slider-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-slider-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-slider-label-gapcontrol
label
inset-block-end
inset-block-start
margin-block-end
@media (pointer: coarse)
default
orientation=horizontal
--xh-space-2
--xh-slider-range-bgrangebackgrounddefault--xh-_tone
--xh-slider-range-bg-disabledrangebackgrounddisabled--xh-bg-subtle-hover-opaque
--xh-slider-range-bg-invalidrangebackgroundinvalid--xh-border-invalid
--xh-slider-range-radiusrangeborder-radiusdefault--xh-shape-pill
--xh-slider-thumb-bgthumbbackgrounddefault--xh-bg-surface
--xh-slider-thumb-bg-disabledthumbbackgrounddisabled--xh-bg-surface
--xh-slider-thumb-borderthumbborderdefault--xh-_tone
--xh-slider-thumb-border-disabledthumbborder-colordisabled--xh-bg-subtle-hover-opaque
--xh-slider-thumb-border-invalidthumbborder-colorinvalid--xh-border-invalid
--xh-slider-thumb-radiusthumbborder-radiusdefault--xh-shape-circle
--xh-slider-thumb-sizecontrol
root
thumb
block-size
inline-size
inset-block-end
inset-block-start
inset-inline
margin-block-end
margin-block-start
margin-inline-start
@media (pointer: coarse)
default
orientation=horizontal
orientation=vertical
size=lg
size=sm
--xh-track-thumb-size-lg
--xh-track-thumb-size-md
--xh-track-thumb-size-sm
--xh-slider-tick-bgtickbackgrounddefault--xh-bg-surface
--xh-slider-tick-bordertickborderdefault--xh-bg-subtle-hover
--xh-slider-tick-border-activetickborder-colorpassed--xh-_tone
--xh-slider-tick-border-active-disabledtick
tick-group
border-colordisabled
passed
--xh-bg-subtle-hover-opaque
--xh-slider-tick-border-disabledtick
tick-group
border-colordisabled--xh-bg-subtle
--xh-slider-tick-label-fgtick-labelcolordefault--xh-fg-subtle
--xh-slider-tick-label-fg-activetick-labelcolorpassed--xh-fg-default
--xh-slider-tick-label-fg-disabledtick-group
tick-label
colordisabled--xh-fg-disabled
--xh-slider-tick-label-font-sizetick-labelfont-sizedefault--xh-text-caption-size
--xh-slider-tick-label-gaproot
tick-label
margin-block-start
margin-inline-start
default
orientation=vertical
--xh-space-1
--xh-slider-tick-radiustickborder-radiusdefault--xh-shape-circle
--xh-slider-tick-sizetickblock-size
inline-size
default--xh-space-2
--xh-slider-track-bgtrackbackgrounddefault--xh-bg-subtle-hover
--xh-slider-track-bg-disabledtrackbackgrounddisabled--xh-bg-subtle
--xh-slider-track-radiustrackborder-radiusdefault--xh-shape-pill
--xh-slider-track-thicknessroot
track
block-size
inline-size
orientation=horizontal
orientation=vertical
size=lg
--xh-stroke-strong
--xh-stroke-thick
--xh-slider-value-text-bgvalue-textbackgrounddefault--xh-_tone
--xh-slider-value-text-fgvalue-textcolordefault--xh-_tone-on
--xh-slider-value-text-font-sizevalue-textfont-sizedefault--xh-text-caption-size
--xh-slider-value-text-offsetvalue-textmargin-block-end
margin-inline
default
orientation=vertical
--xh-space-2
--xh-slider-value-text-pxvalue-textpadding-inlinedefault--xh-space-2
--xh-slider-value-text-pyvalue-textpadding-blockdefault--xh-space-0_5
--xh-slider-value-text-radiusvalue-textborder-radiusdefault--xh-shape-control
--xh-slider-vertical-lengthcontrolblock-sizeorientation=vertical10rem

Released under The MIT License