Slider

Maintainer:
Arucard89
GitHub
tooltipDisplay
disabled
validationState
errorMessage
size
min
max
step
marks
import {Slider} from '@gravity-ui/uikit';

The slider is a customizable and responsive React component that allows users to select a single value or a range of values from a specified data set.

Slider variations

Single slider

This is a slider with one handle to select a single value. It is used by default.

0100
Selected value: 0
<Slider />

Range slider

This is slider with two handles to select a range. To use it, set defaultValue (for an uncontrolled slider) or value (for a controlled one) for the array.

0100
Selected value: 20,40
<Slider defaultValue={[20, 40]} />

States

Disabled

This is a state of a Slider where you do not want to allow the user to work with this component.

0100
Selected value: 0
<Slider disabled={true} />

Error

This Slider state is for incorrect user input. To change the Slider appearance, use the validationState property with the "invalid" value. Optionally, you can provide an error message through the errorMessage property. This message text will be rendered under the slider.

0100
Selected value: 0
0100
Error message
Selected value: 0
<Slider validationState={"invalid"} />
<Slider validationState={"invalid"} errorMessage="Error message" />

Size

Use the size property to manage the Slider size. The default size is m.

0100
Selected value: 0
0100
Selected value: 0
0100
Selected value: 0
0100
Selected value: 0
<Slider size="s" />
<Slider size="m" />
<Slider size="l" />
<Slider size="xl" />

Value

Minimum and maximum value

The min and max properties define the limits of the range the Slider can handle. These properties are essential for setting the boundaries of the selectable values.

10100
Selected value: 10
050
Selected value: 0
2060
Selected value: 20
<Slider min={10} />
<Slider max={50} />
<Slider min={20} max={60} />

Step

The step property determines the increments within the minimum and maximum value range. This means how much the value changes with a single slider move.

0100
Selected value: 0
<Slider step={10} />

Marks

The marks property is utilized in Slider component to specify visual markers along the slider that help to indicate various points between the minimum and maximum value. This property enhances the usability and visual interface of the slider, especially for denoting specific intervals. By default it is 2 (min and max values). You can use it in 2 different ways:

  • the amount of visual markers along the slider
0102030405060708090100
Selected value: 0
<Slider marks={11} />
  • the array of marker values along the slider
0100
Selected value: 0
<Slider marks={[0, 50, 100]} />

0 or empty array [] value in marks property hide all marks from Slider.

0100
Selected value: 0
<Slider marks={0} />

The mark value is available for selection, even if it does not match the step value condition

You are able to change display format of marks values by using marksFormat property.

Define available values

You can set step property to null to define a set of specific values that the slider can handle, as opposed to a continuous range. This is particularly useful when only certain discrete values are valid for selection. In that case properties min, max and marks allows specifying an array of numbers representing the exact values that users are allowed to select using the Slider.

0100
Selected value: 0
<Slider marks={[10, 20, 50, 55, 65, 80]} step={null}/>

Start point

The startPoint property allows you to set the start point of the track. It uses the minimal Slider value by default. It will be ignored if you use Slider with range values or if you set inverted property.

0100
Selected value: 0
<Slider startPoint={50} />

Inverted

The inverted property allows you to set the inverted view of the Slider's track. By default (of false) Slider shows interval from min to handle. If true then it indicates interval from pin to max. Only for single Slider. Property startPoint will be ignored.

0100
Selected value: 0
<Slider inverted />

Tooltip

The tooltipDisplay property is used in Slider component to control the display behaviour of a tooltip that shows the current value as the user interacts with the slider. auto value shows tooltip only when Slider's handle are hovered by cursor or focused.

0
0100
Selected value: 0
<Slider tooltipDisplay="on" />

You are able to change display format of tooltip value by using tooltipFormat property. If you don't specify tooltipformat then will be used marksFormat to display the value in tooltip.

Properties

NameDescriptionTypeDefault
apiRefRef to Slider's component props of focus and blurRefObject<SliderRef>
autoFocusThe control's autofocus attributeboolean
classNameThe control's wrapper class namestring
defaultValueThe control's default value, used when the component is not controlled. It uses the minimal Slider value by default.number [number, number]
disabledIndicates that the user cannot interact with the controlbooleanfalse
errorMessageText of an error to showstring
marksText marks under the slider. Could be set to the amount of the slider's marks, or could be set to the array of values which should have marks. 0 or empty array value hides all marks.number number[]2
marksFormatFormatter for the mark's displayed value(value: number) => string
maxThe maximum value of the component.number100
minThe minimum value of the component.number0
onBlurFires when the control lost focus. Provides focus event as a callback's argument((e: FocusEvent<HTMLDivElement, Element>) => void)
onUpdateFires when the slider’s value is changed by the user. Provides change event as an callback's argument((value: number | [number, number]) => void)
onUpdateCompleteFires when ontouchend or onmouseup is triggered. Provides change event as an callback's argument((value: number | [number, number]) => void)
onFocusFires when the control gets focus. Provides focus event as a callback's argument((e: FocusEvent<HTMLDivElement, Element>) => void)
sizeThe size of the control"s" "m" "l" "xl""m"
stepValue to be added or subtracted on each step the slider makes. Can be set to null to make marks as steps.number null1
startPointStart point of the track. Ignored for range slider and for inverted slider.number
invertedSlider with inverted track (from handle to max).boolean
tabIndexThe control's tabIndex attributenumber [number, number]
tooltipDisplayThe tooltip's display behaviouroff on autooff
tooltipFormatFormatter for the tooltip's displayed value. Uses marksFormat if not set(value: number) => string
validationStateValidation state"invalid"
valueThe value of the controlnumber [number, number]