Skip to content

Slider

The Slider component allows users to select a numeric value from a specified range by dragging a handle along a track.

To use the Slider component, specify the minimum (min), maximum (max), initial value (value), and step size (step).

import Slider from '@components/Basic/Slider/Slider';
const App = () => {
return (
<>
<Slider min={0} max={100} value={35} step={1} />
</>
);
};
export default App;
Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the component’s root element.
classstring""Additional CSS classes to apply to the component
refSliderRef | undefinedundefinedA reference to the component that gives you access to its methods and the underlying HTML element. Useful if you need to set the value of the slider programmatically.
valuenumberundefinedThe current value of the slider. Use this to control or set the slider’s position.
minnumberundefinedThe minimum value that the slider can select.
maxnumberundefinedThe maximum value that the slider can select.
stepnumberundefinedThe amount by which the slider value changes when the handle is moved. Determines the granularity of the slider.
onChange(value: number) => voidundefinedA function that is called every time the slider’s value has changed. It can be used to retrieve the up to date value of the slider.
MethodParametersReturn ValueDescription
changeValue newValue: numbervoidSets new value for the slider

Customizes the slider’s track. Use this slot to apply custom classes or styles to the track area of the slider.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the slider track.
classstring""Additional CSS classes to style the slider track.
import Slider from '@components/Basic/Slider/Slider';
const App = () => {
return (
<>
<Slider min={0} max={100} value={35} step={1}>
<Slider.Track style={{'background-color': 'red'}}></Slider.Track>
</Slider>
</>
);
};
export default App;

Customizes the filled portion of the slider track that visually represents the current value. Use this slot to apply custom styles or classes to the fill area.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the slider fill.
classstring""Additional CSS classes to style the slider fill.
import Slider from '@components/Basic/Slider/Slider';
const App = () => {
return (
<>
<Slider min={0} max={100} value={35} step={1}>
<Slider.Fill style={{'background-color': 'red'}}></Slider.Fill>
</Slider>
</>
);
};
export default App;

Customizes the draggable handle of the slider. Use this slot to apply custom styles or classes to the slider handle.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the slider handle.
classstring""Additional CSS classes to style the slider handle.
import Slider from '@components/Basic/Slider/Slider';
const App = () => {
return (
<>
<Slider min={0} max={100} value={35} step={1}>
<Slider.Handle style={{'background-color': 'red'}}></Slider.Handle>
</Slider>
</>
);
};
export default App;

The Slider.Thumb slot renders a small rectangular element above the handle that displays the current value of the slider. Use this slot to customize the appearance or content of the value indicator.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the slider thumb (value indicator).
classstring""Additional CSS classes to style the slider thumb.
import Slider from '@components/Basic/Slider/Slider';
const App = () => {
return (
<>
<Slider min={0} max={100} value={35} step={1}>
<Slider.Thumb class={styles['Custom-Thumb']} />
</Slider>
</>
);
};
export default App;

The Slider.Grid slot displays a visual indicator of progress along the slider’s range, dividing the track into evenly spaced segments called “pols.” Each pol marks a separation between the minimum and maximum values, helping users see how far the current value has moved.

You can control the number of main pols (with value labels) using the pols prop.
Additionally, by enabling the pols-without-text prop, smaller unlabeled pols are rendered between the main pols for finer granularity and enhanced visual feedback.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the grid container.
classstring""Additional CSS classes to style the grid container.
polsnumber5Number of main pols (segments with value labels) to display along the slider track.
pols-without-textnumber5If prop is present, it renders smaller unlabeled pols between main pols for finer granularity.
pol-styleJSX.CSSProperties{}Inline styles to apply directly to each pol (segment marker).
pol-classstring""Additional CSS classes to style each pol (segment marker).
pol-value-styleJSX.CSSProperties{}Inline styles for poles displaying the slider’s current value.
pol-value-classstring""Additional CSS classes for poles displaying the slider’s current value.
import Slider from '@components/Basic/Slider/Slider';
const App = () => {
return (
<>
<Slider min={0} max={100} value={35} step={1}>
<Slider.Grid pol-style={{'background-color': 'red', 'color': 'green'}} pols={5} pols-without-text={7} />
</Slider>
</>
);
};
export default App;
  • To get the current value of the Slider component, use the onChange prop.
  1. Define a state variable (e.g., using createSignal) to store the slider value.
  2. Pass a callback to the onChange prop that updates this state variable.
  3. Use the state variable wherever you need the slider’s value.
import Slider from '@components/Basic/Slider/Slider';
import { createSignal} from 'solid-js';
const App = () => {
const [sliderValue, setSliderValue] = createSignal(50);
return (
<>
<Slider onChange={(value) => setSliderValue(value)} value={50} max={100} min={0} step={1} />
<div>{sliderValue()}</div>
</>
);
};
export default App;

Set the value of the slider programmatically

Section titled “Set the value of the slider programmatically”

The Slider component lets you set the value through code.

  1. Declare a ref variable with type SliderRef and pass it to the Slider component.
  2. Call ref.changeValue() from anywhere (e.g., a keyboard event or external button) to set the value programmatically.
import Slider { SliderRef } from '@components/Basic/Slider/Slider';
const App = () => {
let sliderRef!: SliderRef;
const handleKeyPress = (e: KeyboardEvent) => {
if (e.keyCode !== 13) return
sliderRef.changeValue(100);
}
return (
<>
<Slider value={50} max={100} min={0} step={1} />
</>
);
};
export default App;

You can customize the grid pols that display values using the pol-value-style and pol-value-class properties of the Slider.Grid slot.

This is particularly useful for adjusting the font size, width, or text wrapping behavior of the pol value elements.

By default, the text wraps to break words based on the width of the pol value element.

In the following example, you can see how to modify the font size, width, and disable the overflow-wrap property for the pol value elements.

import Slider from '@components/Basic/Slider/Slider';
const App = () => {
return (
<Slider min={0} max={100} value={35} step={1}>
<Slider.Grid pol-value-style={{'font-size': '0.9vmax', width: '1.5vmax', 'overflow-wrap': 'normal'}} pol-value-class="custom-pol-value" />
</Slider>
);
};
export default App;