Single-thumb range control built on the native input[type=range] with KtUI lifecycle, optional value output, and a CSS variable for track fill.
Initialize on a wrapper that contains one input[type="range"]. The component stores --kt-range-fill on the root (0–1) so you can drive a visual track or theme styles.
Point data-kt-range-slider-output at a selector for an element whose text updates on input and change (searched under the root first, then document).
Use the native disabled attribute on the range input. The control stays a real form field; avoid replacing it with a non-focusable custom thumb.
Define explicit min, max, and step values to constrain user input to predictable increments.
Use native list and <datalist> to add browser-supported tick references for common values.
Keep the range input in a standard form so submission and readout work with native semantics.
Use external controls to set preset values while keeping slider output in sync.
<div data-kt-range-slider>
<input type="range" min="0" max="100" value="40" />
</div>You may also put data-kt-range-slider directly on the range input. getElement() returns that input.
<input type="range" min="0" max="100" value="40" data-kt-range-slider />If a wrapper contains more than one range input, the component binds to the first in tree order (avoid duplicate controls in one instance).
| Name | Type | Default | Description |
|---|---|---|---|
data-kt-range-slider | flag | — | Enables auto-init on the element. |
data-kt-range-slider-output | string |
min, max, step, and value use the native attributes on input[type="range"].
| Custom property | Where | Description |
|---|---|---|
--kt-range-fill | Root element passed to the instance | Number from 0 to 1: (value - min) / (max - min). Updated on each input. |
Example (Tailwind-friendly): style={{ width: 'calc(var(--kt-range-fill, 0) * 100%)' }} on an inner bar.
| Method | Description |
|---|---|
new KTRangeSlider(element, options?) | Creates an instance if markup includes a range input. |
getRangeInput() | Returns the controlled HTMLInputElement or null. |
getValue() | Current numeric value from the input. |
| Method | Description |
|---|---|
KTRangeSlider.init() | Initializes [data-kt-range-slider] (except lazy). |
KTRangeSlider.createInstances() | Same discovery; safe to call after DOM updates. |
KTRangeSlider.getInstance(element) | Returns the instance on the root, or null. |
KTRangeSlider.init();
const el = document.querySelector('[data-kt-range-slider]');
const slider = KTRangeSlider.getInstance(el);
console.log(slider?.getValue());Native input and change on the range control still fire. KtUI dispatches:
| Event | When | event.detail.payload |
|---|---|---|
kt.range-slider.input | Native input | { value, min, max } (numbers), plus step when the input has a numeric step (omitted for step="any") |
kt.range-slider.change | Native |
root.addEventListener('kt.range-slider.input', (e) => {
console.log(e.detail.payload.value);
});Focus, keyboard arrows, and screen reader behavior come from the native input[type="range"]. Keep the native input in the tab order and visible.
import {
KTRangeSlider,
type KTRangeSliderConfigInterface,
type KTRangeSliderInterface,
type KTRangeSliderEventPayloadInterface,
} from '@keenthemes/ktui';
const root = document.querySelector<HTMLElement>('[data-kt-range-slider]');
if (!root) {
throw new Error('missing root');
}
const slider: KTRangeSliderInterface | null =
KTRangeSlider.getOrCreateInstance(root, {
output: '#kt-range-slider-value',
} satisfies KTRangeSliderConfigInterface);
if
| — |
| CSS selector for a value label; text updates with the input value. |
data-kt-range-slider-lazy | boolean | false | Skip auto-init; create with getOrCreateInstance or new KTRangeSlider(...). |
getOption(name) | Option from merged config / data attributes. |
getElement() | Root element (wrapper or the input). |
on / off | Instance callback map (see Events). |
dispose() | Removes listeners and clears the instance from KTData. |
KTRangeSlider.getOrCreateInstance(element, config?) | Returns an instance or null if no range input exists. |
changeSame shape as input |