<range-input>

A horizontal slide input with scaling, steps, ticks, support for various units and formatted output display.

Frequency

Import

Import and register the <range-input> custom element, upgrading any instances already in the DOM:

import RangeInput from 'literal/documentation/templates/range-input.js';

Use

You can now write <range-input> elements in your HTML:

<range-input name="ratio" min="-1" max="1" ticks="-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1" value="0">Scale</range-input>
<range-input name="gain" min="-48dB" max="0dB" ticks="-∞dB -48dB -42dB -36dB -30dB -24dB -18dB -12dB -6dB 0dB" scale="log-60dB" display="dB" value="-6dB">Volume</range-input>
<range-input name="frequency" min="20" max="20000" ticks="20Hz 50Hz 100Hz 200Hz 500Hz 1kHz 2kHz 5kHz 10kHz 20kHz" scale="log" display="Hz" value="20Hz">Frequency</range-input>
<range-input name="rating" min="1" max="5" ticks="1 2 3 4 5" step="tick" scale="linear" value="3">Rating</range-input>

Attributes

min ="0"

Value at lower limit of fader. Will interpret string values with recognised units, eg. "0dB" or "200Hz", or numbers.

max ="1"

Value at upper limit of fader. Will interpret string values with recognised units, eg. "0dB" or "200Hz", or numbers.

scale ="linear"

Fader scale. This is the name of a transform to be applied over the range of the fader travel. Possible values are:

ticks

A space or comma separated list of values at which to display tick marks. Values may be listed with or without units, eg:

ticks="0 0.2 0.4 0.6 0.8 1"
ticks="-∞dB -48dB -36dB -24dB -12dB 0dB"

Note that the unicode infinity character is interpreted as Infinity (after unit conversion -∞dB is 0 and 0dB is 1).

Ticks may optionally be given labels, displayed in lieu of the tick value. Labels are written in square brackets following the tick value:

ticks="0 [None] 0.5 [Half] 1 [Full]"

display

The units to display the value in. The output value and all ticks are displayed in this unit. Possible values are:

Display formatters may be added by importing the formatters object:

RangeInput.displayFormats['my-format'] = (format, value) => {
    // Return an object of the form `{ value, unit }`
};

This format may now be used by declaring the display attribute:

display="my-format"

step

Step is either:

Properties

.type

“number” A readonly property with the value "number" (provided for consistency with native form elements, which all have a type).

.min

Value at lower limit of fader. Will interpret string values with recognised units, eg. "0dB" or "200Hz", or numbers.

.max

Value at upper limit of fader. Will interpret string values with recognised units, eg. "0dB" or "200Hz", or numbers.

Parts

::part(label)

Style the label.

::part(tick)

Style the tick marks.

::part(output)

Style the display of the output value.

Contribute

Support development: Sponsor


Built by Stephen Band for Cruncher logo Cruncher.

Documentation set in Euclid and Martian Mono. Fonts used for documentation not included as part of the license covering the use of range-input.