Skip to content

TextSlider

The TextSlider component enables users to select a string value from a predefined set of options by dragging a handle along a track.

To use the TextSlider component, specify the selectable options using the values prop.

import TextSlider from '@components/Basic/TextSlider/TextSlider';
const App = () => {
return (
<TextSlider values={['Easy', 'Medium', 'Hard']} />
);
};
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.
refTextSliderRef | undefinedundefinedA reference to the component, providing access to its methods and the underlying HTML element. Useful for programmatically setting the slider’s value.
valuestringundefinedThe current value of the slider. Use this to control or set the slider’s position.
valuesstring[]undefinedAn array of options that can be selected by dragging the slider’s handle.
onChange(value: string) => voidundefinedA callback function triggered whenever the slider’s value changes. It provides the updated value of the slider.
MethodParametersReturn ValueDescription
changeValuenewValue: stringvoidUpdates the slider’s value. If the new value is not in the values array, a warning is logged to the console.

This slot allows customization of the slider’s track. Use it to apply custom styles or classes to the track area.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles for the slider track.
classstring""Additional CSS classes for the slider track.
import TextSlider from '@components/Basic/TextSlider/TextSlider';
const App = () => {
return (
<TextSlider value="Medium" values={['Easy', 'Medium', 'Hard']} >
<TextSlider.Track style={{ 'background-color': 'red' }} />
</TextSlider>
);
};
export default App;

This slot customizes the filled portion of the slider track, which visually represents the current value. Use it to apply custom styles or classes to the fill area.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles for the slider fill.
classstring""Additional CSS classes for the slider fill.
import TextSlider from '@components/Basic/TextSlider/TextSlider';
const App = () => {
return (
<TextSlider value="Medium" values={['Easy', 'Medium', 'Hard']} >
<TextSlider.Fill style={{ 'background-color': 'red' }} />
</TextSlider>
);
};
export default App;

This slot customizes the draggable handle of the slider. Use it to apply custom styles or classes to the handle.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles for the slider handle.
classstring""Additional CSS classes for the slider handle.
import TextSlider from '@components/Basic/TextSlider/TextSlider';
const App = () => {
return (
<TextSlider value="Medium" values={['Easy', 'Medium', 'Hard']} >
<TextSlider.Handle style={{ 'background-color': 'red' }} />
</TextSlider>
);
};
export default App;

The TextSlider.Thumb slot displays a small rectangular element positioned above the slider’s handle, showing the current value of the slider. You can use this slot to customize the appearance or content of the value indicator.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply to the slider thumb.
classstring""Additional CSS classes for styling the slider thumb.
import TextSlider from '@components/Basic/TextSlider/TextSlider';
const App = () => {
return (
<TextSlider value="Medium" values={['Easy', 'Medium', 'Hard']} >
<TextSlider.Thumb class={styles['Custom-Thumb']} />
</TextSlider>
);
};
export default App;

The TextSlider.Pol slot allows you to customize the appearance of the poles that represent the slider’s selectable values in a grid layout. You can style both the poles and the text displayed on them.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles for the poles. Use this to customize their appearance.
classstring""Additional CSS classes for the poles.
text-styleJSX.CSSProperties{}Inline styles for the text displayed on the poles.
text-classstring""Additional CSS classes for the text displayed on the poles.
import TextSlider from '@components/Basic/TextSlider/TextSlider';
const App = () => {
return (
<TextSlider value="Medium" values={['Easy', 'Medium', 'Hard']} >
<TextSlider.Pol style={{ 'background-color': 'red' }} text-style={{ color: 'green' }} />
</TextSlider>
);
};
export default App;
  • To get the current value of the TextSlider 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 TextSlider from '@components/Basic/TextSlider/TextSlider';
import { createSignal} from 'solid-js';
const App = () => {
const [sliderValue, setSliderValue] = createSignal('Medium');
return (
<>
<TextSlider onChange={(value) => setSliderValue(value)} values={['Easy', 'Medium', 'Hard']} />
<div>{sliderValue()}</div>
</>
);
};
export default App;

Set the value of the text slider programmatically

Section titled “Set the value of the text slider programmatically”

The TextSlider component lets you set the value through code.

  1. Declare a ref variable with type TextSliderRef and pass it to the TextSlider component.
  2. Call ref.changeValue() from anywhere (e.g., a keyboard event or external button) to set the value programmatically.
import TextSlider { TextSliderRef } from '@components/Basic/TextSlider/TextSlider';
const App = () => {
let textSliderRef!: SliderRef;
const handleKeyPress = (e: KeyboardEvent) => {
if (e.keyCode !== 13) return
textSliderRef.changeValue('Easy');
}
return (
<TextSlider value="Medium" values={['Easy', 'Medium', 'Hard']} />
);
};
export default App;