Liking cljdoc? Tell your friends :D

x-slider

A native-input-backed, form-associated, accessible range slider web component.

Tag name

<x-slider></x-slider>

Attributes

AttributeTypeDefaultDescription
valuestring (number)"0"Current value
minstring (number)"0"Minimum value
maxstring (number)"100"Maximum value
stepstring (number | "any")"1"Step increment. "any" disables stepping.
disabledboolean (presence)falseDisables all interaction
readonlyboolean (presence)falseBlocks pointer and keyboard interaction; thumb remains focusable
namestringForm field name
labelstringVisible label text above the slider
show-valueboolean (presence)falseShow the current numeric value beside the label
size"sm" | "md" | "lg""md"Size variant
aria-labelstringAccessible label forwarded to [part=input]
aria-labelledbystringForwarded to [part=input]
aria-describedbystringForwarded to [part=input]

When neither aria-label nor aria-labelledby is set, the label attribute value is used as the aria-label on the native input.


Properties

All properties reflect to their corresponding attributes.

PropertyTypeReflects attribute
valuestringvalue
minstringmin
maxstringmax
stepstringstep
disabledbooleandisabled
readOnlybooleanreadonly
showValuebooleanshow-value
namestringname
labelstringlabel
sizestringsize

Events

EventCancelableDetail
x-slider-inputno{ value: number, min: number, max: number }
x-slider-changeno{ value: number, min: number, max: number }

Both events bubble and are composed (cross shadow-DOM boundary).

  • x-slider-input — fires continuously while the user drags.
  • x-slider-change — fires once when the user commits a value (mouseup / touchend).

Parts

PartElementDescription
base<div>Outer wrapper; receives data-size
header<div>Row containing label and value text; hidden when neither is active
label-text<span>Label text
value-text<span>Numeric value display
input<input type="range">The native range input

CSS Custom Properties

PropertyDefault (light)Description
--x-slider-track-colorrgba(0,0,0,0.15)Unfilled track color
--x-slider-fill-color#3b82f6Filled portion color
--x-slider-thumb-color#ffffffThumb background color
--x-slider-thumb-border2px solid #3b82f6Thumb border
--x-slider-thumb-shadow0 1px 4px rgba(0,0,0,0.20)Thumb drop shadow
--x-slider-focus-ring#60a5faFocus ring color
--x-slider-disabled-opacity0.45Opacity when disabled
--x-slider-label-colorrgba(0,0,0,0.60)Label text color
--x-slider-value-colorrgba(0,0,0,0.50)Value text color
--x-slider-radius9999pxTrack and fill border-radius

All properties have sensible dark-mode overrides applied automatically via @media (prefers-color-scheme: dark).

Size-driven internal variables

The size attribute sets CSS custom properties on [part=base]:

SizeTrack height (--_x-slider-track-h)Thumb size (--_x-slider-thumb-sz)
sm4px14px
md6px18px
lg8px22px

Accessibility

  • The native <input type="range"> provides role="slider" automatically.
  • aria-valuemin, aria-valuemax, aria-valuenow are kept in sync on the native input.
  • aria-readonly="true" is set on the input when readonly is present.
  • When disabled, the native input receives the disabled attribute (not just aria-disabled), which removes it from the tab order.
  • readonly does not remove the element from the tab order (keyboard focus is preserved for awareness/copying).

Form association

x-slider is form-associated (formAssociated = true). The current value is submitted with the form under the name attribute. Supports formResetCallback (resets value to 0) and formDisabledCallback.


Usage examples

Basic slider

<x-slider value="50" min="0" max="100"></x-slider>

With label and visible value

<x-slider label="Volume" show-value value="70" min="0" max="100"></x-slider>

Custom range and step

<x-slider min="-50" max="50" step="5" value="0"></x-slider>

Fractional step

<x-slider min="0" max="1" step="0.01" value="0.5"></x-slider>

Disabled

<x-slider value="30" disabled></x-slider>

Readonly

<x-slider value="60" readonly></x-slider>

Sizes

<x-slider size="sm" value="40"></x-slider>
<x-slider size="md" value="40"></x-slider>
<x-slider size="lg" value="40"></x-slider>

Custom theme

<x-slider
  style="
    --x-slider-fill-color: #22c55e;
    --x-slider-thumb-border: 2px solid #22c55e;
    --x-slider-focus-ring: #86efac;
  "
  value="60"
  label="Progress"
  show-value>
</x-slider>

In a form

<form>
  <x-slider name="brightness" value="80" min="0" max="100" label="Brightness" show-value></x-slider>
  <button type="submit">Save</button>
</form>

JavaScript API

const slider = document.querySelector('x-slider');

// Read/write properties
slider.value = '50';
slider.min = '0';
slider.max = '200';
slider.step = '10';
slider.disabled = true;
slider.readOnly = false;
slider.showValue = true;
slider.label = 'Volume';
slider.size = 'lg';

// Listen for events
slider.addEventListener('x-slider-input', (e) => {
  console.log('dragging:', e.detail.value);
});
slider.addEventListener('x-slider-change', (e) => {
  console.log('committed:', e.detail.value);
});

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close