Component

Slider

安装 Installation

npx timkit add slider --yes --framework react

用法 Usage

import { Slider } from "@/components/ui/slider"

className 与 variant、size 可以一起用。字段以 timkit agent inspect slider --json 的 props 为准。

示例

Examples

一次看一个示例。左侧按名称筛选,预览里可切换源码和框架。

27 / 27

Slider · Simple slider

Loading preview...

结构化 API

Structured API

与 UCS schema 对齐的 props、逻辑机与多框架运行时。

Component

slider

Logic

zag / slider

Runtime Frameworks

ReactVueWeappHTML

Supported Platforms

WebWeChat Mini Program

Configuration

PropTypeDefaultDescription
logic.provider*
enum (zag | native | none)
zagState and interaction provider used by this component.
logic.machine
string
sliderUnderlying state machine identifier when provider is zag.
platforms*
array
Web, WeChat Mini ProgramPlatforms officially supported by this schema.
frameworks*
array
React, Vue, Weapp, HTMLFramework demos/code currently available in registry files.
dependencies
array
@timui/core, @zag-js/reactRuntime package dependencies required by this registry item.
optionalPeerDependencies
array
-Optional peer dependencies used by this registry item.
registryDependencies
array
https://ui.timkit.cn/r/tooltip.json, use-machineDependent Timkit registry components/hook entries.

Props

PropTypeDefaultDescription
value
number
-The controlled value.
disabled
boolean
falseWhether the slider is disabled.
readOnly
boolean
falseWhen true, value changes are ignored.
min
number
0The minimum value.
max
number
100The maximum value.
step
number
1The step value.
orientation
enum (horizontal | vertical)
horizontalHorizontal sliders move with Left and Right. Vertical sliders move with Up and Down.

Events

PropTypeDefaultDescription
onValueChange
event
-Callback called when value changes.

TypeScript

来自 TypeScript 导出。

PropTypeDefaultDescription
id
string
-Input behavior configuration for id.
showTooltip
boolean
-Whether to show thumb tooltip labels.
modelValue
number
-The controlled value bound via `v-model` (Vue specific).
defaultValue
number
-The default value of the component when uncontrolled.
ids
enum (ids)
-The ids of the elements in the slider. Useful for composition.
dir
enum (dir)
-The text direction.
name
string
-Accessible labels for slider thumbs. / 'aria-label'?: slider.Props['aria-label'] /** Accessible labelled-by ids for slider thumbs. / 'aria-labelledby'?: slider.Props['aria-labelledby'] /** The name associated with each slider thumb.
form
string
-The associated form id.
invalid
boolean
-Whether the slider is invalid.
minStepsBetweenThumbs
number
-The minimum steps between thumbs for multi-thumb sliders.
origin
enum (start | center | end)
-The origin of the slider range.
thumbAlignment
enum (contain | center)
-Thumb alignment relative to track.
thumbSize
enum (thumbSize)
-Thumb dimensions.
thumbCollisionBehavior
enum (none | push | swap)
-Collision behavior when thumbs cross.
getAriaValueText
enum (getAriaValueText)
-Function that returns a readable value for a thumb.
tooltipContent
event
-Custom formatter for tooltip labels.
onFocusChange
enum (onFocusChange)
-Callback fired when focused thumb changes.
onValueChangeEnd
event
-Callback fired when value commit ends.

Slots

PropTypeDefaultDescription
default
slot
-Default slot content rendered inside the component root.

Parts

PropTypeDefaultDescription
root*
root
-The slider container
track
part
-The slider track
range
part
-The filled part of the track
thumb
part
-The handler to slide
This API reference is generated from `/packages/core` component schemas to keep React/Vue/Weapp docs consistent.

该组件尚无扩展说明文档。

键盘与焦点

Keyboard

跨 React、Vue 与小程序共享的交互与可读名称约定。

  • ArrowRight increases the value by one step.
  • PageUp increases by ten steps.
  • PageDown decreases by ten steps.
  • Shift with an arrow moves by ten steps.
  • Home jumps to the minimum.
  • End jumps to the maximum.
  • The slider receives the keys.
  • The current value is visible.
  • Two thumbs read both values, separated by to.
  • An omitted name is Value.
  • A passed aria-label names the slider. aria-labelledby suppresses the omitted name.
  • A passed aria-label stays.
  • On the mini program, a passed aria-label stays, and aria-label is left off when only aria-labelledby is set.
  • On the mini program, the slider exposes its minimum, maximum, and current value.
  • An empty value does not set aria-valuenow.
  • On the mini program, a read-only slider sets aria-readonly.

行为契约

Contract

props、默认值和运行时状态。

  • When read-only, value changes are ignored.
  • Horizontal sliders move with Left and Right.
  • Vertical sliders move with Up and Down.
  • A later min or max keeps the value inside that range.