@19h47/slider

Multi-thumb range slider controller (APG-style). One instance controls both thumbs and prevents crossing.

Getting started

Import the controller and initialize it with a rail element that contains 2 thumbs.

import Slider from '@19h47/slider'

const rail = document.querySelector('.rail')
const slider = new Slider(rail, { orientation: 'horizontal', width: 24, height: 24 })

slider.init()

Markup

The rail must contain exactly 2 elements with role="slider". Order matters: first = max, second = min.

<div class="rail">
  <button role="slider" class="max" aria-label="Maximum" aria-valuemin="0" aria-valuemax="35" aria-valuenow="35" aria-orientation="horizontal"></button>
  <button role="slider" class="min" aria-label="Minimum" aria-valuemin="0" aria-valuemax="35" aria-valuenow="0" aria-orientation="horizontal"></button>
</div>

Options

Option Type Default Description
orientation 'horizontal' | 'vertical' 'horizontal' Slider orientation.
width number 24 Thumb width (px).
height number 24 Thumb height (px).
direction 'auto' | 'ltr' | 'rtl' 'auto' Horizontal axis direction (uses computed CSS direction in auto).

Events

The rail dispatches a Slider.change event with { min, max, active }.

rail.addEventListener('Slider.change', (event) => {
  const { min, max, active } = event.detail
  console.log({ min, max, active })
})

Demos

Values update via Slider.change

Horizontal range

35
0

Horizontal range (RTL)

35
0

Vertical (0 → 35)

35
0

Vertical (10 → 1000)

803
56

Vertical (0 → 35)

35
0

Vertical (0 → 10000)

10000
0