Elastic Slider

A slider with rubber-band dragging, step support, value formatting, and keyboard controls.

motion-svruned

Installation

pnpm dlx shadcn-svelte@latest add http://sveltekit-prerender/r/elastic-slider.json

Usage

usage.svelte

Features

  • Track stretches with rubber-band tension when dragged past bounds
  • Snaps magnetically to exact steps or continuous deciles
  • Inline label and value text dynamically fade to avoid handle overlap
  • Supports keyboard navigation and respects prefers-reduced-motion

Examples

Default value

Set the initial value while letting the slider manage its own state.

Controlled value

Keep the value in parent state with value and onValueChange.

Currency formatting

Format the displayed value with Intl.NumberFormat.

Units and precision

Combine a fractional step with a custom unit and fixed precision.

Discrete steps

Use a short integer range for exact, visible stops.

Negative range

Configure a range that spans values below and above zero.

Live UI control

Connect multiple controlled sliders to a visual preview.

Props

ElasticSlider

Controlled or uncontrolled elastic value slider.

NameTypeDefaultDescription
labelstringrequiredLabel displayed inside the slider track.
valuenumberundefinedControlled slider value.
defaultValuenumberminInitial value when the slider is uncontrolled.
onValueChange(value: number) => voidundefinedCalled after drag, click, or keyboard interaction changes the value.
minnumber0Minimum allowed value.
maxnumber1Maximum allowed value.
stepnumber0.01Increment used when snapping values.
formatValue(value: number) => stringundefinedFormats the value displayed in the track.
refHTMLDivElement | nullnullBindable reference to the outer slider element.
classstringundefinedAdditional classes applied to the slider.