Slider

May 31, 2019 ยท View on GitHub

Select a value from a continuous or discrete range of values by moving the slider thumb. Optimized for mobile.

Main features

  • Touch support
  • Continuous or discrete slider by setting the step size (adjustable to any value including 0)
  • Optional tick marks
  • Optional pin label
  • Custom thumb element (for instance SVG)
  • Optionally disable clicking on track
  • Keyboard control

Usage

Keyboard control

Press TAB to navigate to the slider thumb - it will show a highlight. Press ENTER to execute the equivalent of a click.

  1. Start keyboard control by tabbing to the slider thumb. It will show a focus state.
  2. Keyboard interaction follows the WAI-ARIA slider authoring practices.
KeysResult
Right ArrowIncrease the value of the slider by one step.
Up ArrowIncrease the value of the slider by one step.
Left ArrowDecrease the value of the slider by one step.
Down ArrowDecrease the value of the slider by one step.
HomeSet the slider to the first allowed value in its range.
EndSet the slider to the last allowed value in its range.
Page UpIncrement the slider by 10 steps.
Page DownDecrement the slider by 10 steps.
Shift, and Right Arrow or Up ArrowIncrement the slider by 10 steps.
Shift, and Left Arrow or Down ArrowDecrement the slider by 10 steps.

The amount of change depends on the step size. This can be set with option step (default: 1). Also the values for first allowed value (min) and last allowed value (max) can be set.

Options

Slider specific options

ParameterRequiredTypeDefaultDescription
defaultValueoptionalNumber0Initial slider value
disabledoptionalBooleanfalseSet to true to make the slider read only
iconoptionalString, hyperscript or componentAdds a String, hyperscript or component to the slider control
interactiveTrackoptionalBooleantrueSet to false to prevent clicking on the track
maxoptionalNumber100Maximum slider value
minoptionalNumber0Minimum slider value
onChangeoptionalFunction ({ value: number }) => undefinedCallback function that receives the slider state
pinoptionalBooleanfalseUse with step; on click shows a pin shape with the current value
stepSizeoptionalNumber1Step size; set to 0 for a continuous (smooth) slider
ticksoptionalBooleanfalseShow a tick for each step; limited to 100
valueoptionalNumber0Managed Slider value (see: Handling state)

Common component options

ParameterRequiredTypeDefaultDescription
afteroptionalString, hyperscript or componentExtra content after main content; note that this content is placed right of preceding elements with a higher stacking depth
beforeoptionalString, hyperscript or componentExtra content before main content; note that this content is placed left of subsequent elements with a lower stacking depth
classNameoptionalStringExtra CSS class appended to pe-slider
elementoptionalString"div"HTML element tag
eventsoptionalObjectOptions object containing one or more standard events such as onclick (React: onClick)
idoptionalStringHTML element id
tabindex (React: tabIndex)optionalInteger0Tab index
toneoptionalString: "dark" or "light"Renders the component light on dark (sets class pe-dark-tone); use "light" to locally inverse (sets class pe-light-tone)

Composition

Slider is optionally composed from:

  • Icon (with option icon)

CSS classes

Design considerations

  • With both usability and theming in mind, no range input element is created (other than for instance Material Design Lite). The range input has limited styling options, for instance it is not possible to create a large enough click area for the slider thumb (without making the thumb itself enormous). Using a different image for the thumb is out of the question. This Slider component is composed from DIV elements instead.
  • Vertical orientation is not supported because it is not part of the design specification. The same goes for multi-thumb support.

Future

  • Right to left support
  • Full ARIA specs