Slider

The Slider is used to allow users to make selections from a range of values.

Import#

Chakra UI exports 5 components for Slider:

  • Slider: The wrapper that provides context and functionality for all children.
  • SliderTrack: The empty part of the slider that shows the track.
  • SliderFilledTrack: The filled part of the slider.
  • SliderThumb: The handle that's used to change the slider value.
  • SliderMark: The label or mark that shows names for specific slider values
import {
Slider,
SliderTrack,
SliderFilledTrack,
SliderThumb,
SliderMark,
} from '@chakra-ui/react'

Usage#

Sliders reflect a range of values along a bar, from which users may select a single value. They are ideal for adjusting settings such as volume, brightness, or applying image filters.

Note: We recommend adding a aria-label or aria-labelledby prop to provide an accessible label for the Slider.

Changing the slider color scheme#

Changing the slider orientation#

Customizing the Slider#

Slider component was designed to be composed to make it easy for you to customize its styles.

Discrete Sliders#

Discrete sliders allow you to snap to predefined sets of values. This can be accomplished using the step prop.

Slider with custom labels and marks#

You can have custom labels and marks by using SliderMark component

And you can also use Tooltip with SliderThumb

Getting the final value when dragging the slider#

Dragging the slider can trigger lots of updates and the user might only be interested in the final result after sliding is complete. You can use onChangeEnd for this.

<Slider aria-label='slider-ex-5' onChangeEnd={(val) => console.log(val)}>
<SliderTrack>
<SliderFilledTrack />
</SliderTrack>
<SliderThumb />
</Slider>

Configure thumb focus with focusThumbOnChange#

By default SliderThumb will receive focus whenever value changes. You can opt-out of this behavior by setting the value of focusThumbOnChange to false. This is normally used with a "controlled" slider value.

<Slider aria-label='slider-ex-5' value={value} focusThumbOnChange={false}>
<SliderTrack>
<SliderFilledTrack />
</SliderTrack>
<SliderThumb />
</Slider>

useSlider#

The useSlider hook is exported with state and focus management logic for use in creating tailor-made slider component for your application. Read more about the useSlider hook here.

Proudly made inNigeria by Segun Adebayo

Deployed by â–² Vercel