Components/Slider

Slider

A control for choosing a number within a range.

VerifiedSince 0.3.4

Usage

Basic

Loading demo...

Show Value

Loading demo...

Formatted Display

formatValue formats the side readout, and the tooltip too when tooltipFormatter is absent.

Loading demo...

Disabled

Loading demo...

Elastic Tooltip

tooltipTilt tilts and trails the tooltip with pointer speed and acceleration; tooltipJelly adds a wobble on top.

Loading demo...

Best Practices

  • Use a slider for continuous or near-continuous numbers; use TxSegmentedSlider when each stop has its own meaning.
  • Put units in nearby text or in formatValue / tooltipFormatter, never in modelValue.
  • Keep min, max, and step stable while the user drags, or the thumb jumps.
  • Reserve tilt and jelly motion for exploratory tuning surfaces, not dense forms.
  • Resize the pill with --tx-slider-surface-width / --tx-slider-surface-size, not --tx-slider-thumb-size alone; to drop the thumb, set thumbSurface=false before zeroing it.

API Reference

Props

PropTypeDefaultDescription
modelValuenumber0Current value; displayed clamped to min..max.
minnumber0Minimum value.
maxnumber100Maximum value.
stepnumber1Step size.
disabledbooleanfalseDisables the slider and hides the tooltip.
activebooleantrueWhen false, suspends observers, global tracking, and motion; the value and disabled are untouched.
showValuebooleanfalseShows the current value beside the slider.
formatValue(value: number) => string-Formats the side readout.
thumbSurfacebooleantrueAlways-visible capsule thumb with the Radio indicator's material and jelly; false gives a flat disc.
thumbVariant'solid' | 'blur' | 'glass''blur'Capsule body: solid is opaque, blur thins and frosts the track below, glass turns refractive while held.
showTooltipbooleantrueShows the tooltip when its trigger condition is met.
tooltipTrigger'drag' | 'hover' | 'always''drag'When the tooltip shows.
tooltipFormatter(value: number) => string-Formats the tooltip text.
tooltipPlacement'top' | 'bottom''top'Puts the tooltip above or below the thumb.
tooltipTiltbooleanfalseEnables velocity-based follow, tilt, offset, squash, and skew.
tooltipTiltMaxDegnumber18Maximum tilt angle.
tooltipOffsetMaxPxnumber28Maximum horizontal offset.
tooltipAccelBoostnumber0.65How much acceleration adds to the motion's intensity.
tooltipSpringStiffnessnumber320Spring stiffness for follow, offset, and tilt.
tooltipSpringDampingnumber24Spring damping for follow, offset, and tilt.
tooltipMotion'blur' | 'fade' | 'none''blur'Enter/leave motion; none skips the transition wrapper.
tooltipMotionDurationnumber160Enter/leave duration in ms; negative values count as 0.
tooltipMotionBlurPxnumber10Blur radius of the blur motion in px; negative values count as 0.
tooltipDistortSkewDegnumber8Maximum skew while moving.
tooltipJellybooleantrueAdds an acceleration-triggered wobble on top of the tilt.
tooltipJellyFrequencynumber8.5Wobble frequency in Hz.
tooltipJellyDecaynumber10Wobble decay; higher settles faster.
tooltipJellyRotateDegnumber10Maximum wobble rotation.
tooltipJellySkewDegnumber12Maximum wobble skew.
tooltipJellySquashnumber0.16Maximum wobble squash.
tooltipJellyTriggerAccelnumber2800Acceleration threshold that starts the wobble.

Events

EventParamsDescription
update:modelValuenumberFires on native input with the clamped value.
changenumberFires on native change.

Overview

  • With the default thumbSurface, the native thumb becomes a hit area as wide as the capsule; the keyboard focus ring is drawn on the capsule, except after a drag-initiated focus.
  • active=false, KeepAlive deactivation, and unmount all stop frame work, detach global pointer listeners, and disconnect size observers; resuming re-observes the current layout.
  • Reduced-motion changes apply immediately, even mid-drag: deformation stops while the native input and static readouts remain.

Technologies

  • The thumb deforms with the same jelly maths as the Radio indicator, from packages/tuffex/packages/utils/animation/jelly.ts.
  • No slots are exposed: tooltip, thumb, track, and readout render internally so pointer math and tooltip transforms stay in sync.
  • Source: packages/tuffex/packages/components/src/slider/.
查看源码
packages/tuffex/packages/components/src/slider/index.ts