Slider Field¶
A range input with a readout of its value. The readout is an output element and the input carries aria-valuetext with the same text.
Decision¶
| When | Use |
|---|---|
| A value in a small range where the position matters, such as an opacity | Slider Field |
| A value where the user needs an exact number | Number Unit Field |
Usage¶
import { createSliderField } from './configurationpage?name=myplugin_stolon.js';
var alpha = createSliderField({ min: 0, max: 255, value: 255, label: 'Opacity', onChange: function (value) { preview(value); } });
container.appendChild(alpha.element);
Classes: stolon-slider, stolon-slider-value. The handle is { element, input, getValue, setValue, destroy }.
States and Modifiers¶
minis 0,maxis 100, andstepis 1 by default.valuedefaults tomin. Aminabovemaxswaps the two.prefixandsuffixgo around the readout number, such as'%'.showValue: falsehides the readout.getValue()returns a number.onChange(value)runs as the slider moves.labelsets the slider's accessible name, "Value" by default.- The input is a native range, so the arrow keys, Home, and End work. The readout has a fixed minimum width so the slider does not jump.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
createSliderField¶
function createSliderField(options?: SliderFieldOptions): SliderFieldHandle
A range input with a readout of its value. The readout is an output element and the input carries aria-valuetext with the same text.
| Option | Type | What it does |
|---|---|---|
value |
number | string |
first value (default min) |
min |
number | string |
lowest value (default 0) |
max |
number | string |
highest value (default 100), and a min above max swaps the two |
step |
number | string |
step (default 1) |
prefix |
string |
text before the readout number [optional] |
suffix |
string |
text after the readout number, such as '%' [optional] |
label |
string |
aria-label of the slider (default 'Value') |
showValue |
boolean |
false hides the readout (default true) |
onChange |
(value: number): void |
function(value) called as the slider moves [optional] |
| Handle member | Type |
|---|---|
input |
HTMLInputElement |
getValue |
(): number |
setValue |
(value: number | string): void |
destroy |
(): void |
| Class | What it looks like |
|---|---|
stolon-slider |
Range input with a readout that keeps its width so the slider does not jump |
Example¶
Example Code¶
<!-- title: Slider Field -->
<div id="mount"></div>
<script type="module">
const base = await window.__baseReady;
const view = document.getElementById('view');
const mount = document.getElementById('mount');
mount.appendChild(base.createSliderField({ min: 0, max: 255, value: 128, suffix: ' of 255', label: 'Opacity' }).element);
</script>