Skip to main content

Slider

import { Slider } from '@enmovil/ui-design-system';

Lets the user pick a single value or a range (mode) by dragging a handle along a track. It supports steps, marks, a vertical layout and a reversed direction.

Properties​

PropertyTypeRequiredDefaultAllowed valuesDescription
modestringYes—'range', 'single'range gives two handles and a [start, end] value; single gives one handle and a number value.
valuenumber | [number, number]No——Current value when controlled: a number, or [start, end] in range mode.
defaultValuenumber | [number, number]No——Initial value when uncontrolled: a number, or [start, end] in range mode.
minnumberNo——Smallest selectable value. Defaults to 0.
maxnumberNo——Largest selectable value. Defaults to 100.
stepnumber | nullNo——Amount each move changes the value by. Defaults to 1; with null the handles can only stop on marks.
marksRecord<number, ReactNode>No——Labels shown along the track, keyed by the value they mark.
dotsbooleanNo——Draws a dot on the track at every step.
includedbooleanNo——Highlights the track up to the handle, or between the handles in range mode. On by default; turn it off to show the handles on a plain track, for example with marks.
disabledbooleanNo——Greys out the slider and stops the handles from moving.
verticalbooleanNo——Lays the slider out vertically. Give its container a height.
reversebooleanNo——Reverses the direction, so min is at the right (at the top when vertical).
classNamestringNo——CSS class of the slider. It replaces the component's own enmv-slider class, so the design-system track and handle colours are lost.
styleCSSPropertiesNo——Inline styles of the slider's outer element.
idstringNo——id of the slider's outer element.
percentnumberNo——Not a prop of the component. It appears only in the stories' controls and has no effect.
statusstringNo—'active', 'success', 'normal', 'exception'Not a prop of the component. It appears only in the stories' controls and has no effect.
widthnumberNo——Not a prop of the component. It appears only in the stories' controls and has no effect.
Other attributes

Slider passes 17 further attributes through to the underlying element. They aren't part of the supported API and may change between releases, so use only the properties listed on this page.

Events​

NameSignatureWhen it fires
onChange((value: number) => void) | ((value: [number, number]) => void)Fires continuously while a handle is dragged or moved with the keyboard.
onAfterChange((value: number) => void) | ((value: [number, number]) => void)Older name for onChangeComplete: fires once with the final value when the drag or key press ends. Logs a deprecation warning, so prefer onChangeComplete.
onChangeComplete((value: [number, number]) => void) | ((value: [number, number]) => void)Fires once when the drag or key press ends. Use it for expensive work such as refetching.
onFocusFocusEventHandler<HTMLDivElement>Fires when a handle receives focus.
onBlurFocusEventHandler<HTMLDivElement>Fires when a handle loses focus.

Children​

Slider does not accept children.

Variants​

Loading examples…

Playground​

Change the controls to see how the properties affect the component. Values the controls don't cover come from the simple example.

Loading playground…

Storybook​

Open Slider in Storybook to try every story with the full set of controls.