Slider

The Slider component enables an intuitive selection of values within a designated range. Users can easily adjust their selection by sliding a visual indicator along the track.
Installation
API Reference
This is an illustration of Slider component.
size
orientation
isDisabled
isReversed
<Center w={300} h={100}>
<Slider
defaultValue={30}
size="md"
orientation="horizontal"
isDisabled={false}
isReversed={false}
>
<SliderTrack>
<SliderFilledTrack />
</SliderTrack>
<SliderThumb />
</Slider>
</Center>

Installation

Run the following command:

npx gluestack-ui add slider

API Reference

To use this component in your project, include the following import statement in your file.
import { Slider } from "@/components/ui/slider"
export default () => (
<Slider>
<SliderTrack>
<SliderFilledTrack />
</SliderTrack>
<SliderThumb />
</Slider>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

Slider

It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
onChange
(value: number) => void
-
Function called when the state of the Slider changes.
isDisabled
bool
false
When true, this will disable Slider
isReadOnly
boolean
false
To manually set read-only to the checkbox.
sliderTrackHeight
number
8
To change the slider track height .
defaultValue
number
-
To change the slider value .
minValue
number
-
The slider's minimum value
maxValue
number
-
The slider's maximum value.
value
number
-
The slider's current value.
step
number
-
The slider's step value.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_thumb
Prop to style SliderThumb Component
_track
Prop to style SliderTrack Component
_filledTrack
Prop to style SliderFilledTrack Component

SliderTrack

It inherits all the properties of React Native's Pressable component.

SliderFilledTrack

It inherits all the properties of React Native's View component.

SliderThumb

It inherits all the properties of React Native's View component.

Features

  • Keyboard support for actions.
  • Support for hover, focus and active states.

Accessibility

We have outlined the various features that ensure the Slider component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards.Adheres to the WAI-ARIA design pattern.

Keyboard

  • Tab: Moves focus to the next focusable element.
  • Right Arrow: Increase the value of the slider by one step.
  • Up Arrow: Increase the value of the slider by one step.
  • Left Arrow: Decrease the value of the slider by one step.
  • Down Arrow: Decrease the value of the slider by one step.

Screen Reader

  • VoiceOver: When the slider is focused, the screen reader will announce the slider's value.

Props

Slider component is created using View component from react-native. It extends all the props supported by React Native View, utility props and the props mentioned below.

Slider

Name
Value
Default
orientation
horizontal | vertical
horizontal
isReversed
true | false
false
size
sm | md | lg
md

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

Slider with Orientation

An example of the Slider component being used with the Slider with Orientation feature to customize the orientation of the slider, providing flexibility in the direction of sliding and input for numerical or adjustable values within a user interface.
function App() {
const [sliderValue, setSliderValue] = React.useState(45)
const handleChange = (value) => {
setSliderValue(value)
}
return (
<Center w="$80">
<Slider
sliderTrackHeight={4}
value={sliderValue}
orientation="vertical"
h={120}
onChange={(value) => {
handleChange(value)
}}
>
<SliderTrack>
<SliderFilledTrack />
</SliderTrack>
<SliderThumb />
</Slider>
</Center>
)
}

Color scheme

A Slider component with a color scheme adds visual styling and customization options, allowing the slider track and handle to be displayed in different colors, enhancing the aesthetic appeal and visual coherence of the slider within a user interface.
function App() {
return (
<VStack space="4xl">
<Center w="$80">
<Slider defaultValue={45} sliderTrackHeight={4}>
<SliderTrack>
<SliderFilledTrack bg="$emerald600" />
</SliderTrack>
<SliderThumb bg="$emerald600" $active-outlineColor="$emerald500" />
</Slider>
</Center>
<Center w="$80">
<Slider defaultValue={45} sliderTrackHeight={4}>
<SliderTrack>
<SliderFilledTrack bg="$amber600" />
</SliderTrack>
<SliderThumb bg="$amber600" $active-outlineColor="$amber500" />
</Slider>
</Center>
<Center w="$80">
<Slider defaultValue={45} sliderTrackHeight={4}>
<SliderTrack>
<SliderFilledTrack bg="$fuchsia600" />
</SliderTrack>
<SliderThumb bg="$fuchsia600" $active-outlineColor="$fuchsia500" />
</Slider>
</Center>
<Center w="$80">
<Slider defaultValue={45} sliderTrackHeight={4}>
<SliderTrack>
<SliderFilledTrack bg="$cyan600" />
</SliderTrack>
<SliderThumb bg="$cyan600" $active-outlineColor="$cyan500" />
</Slider>
</Center>
</VStack>
)
}

With tooltip

A Slider component with a tooltip displays a visual indicator or text overlay that provides real-time feedback on the selected value as users interact with the slider, improving usability and precision in inputting or adjusting numeric or continuous data within a user interface.
function App() {
const [sliderValue, setSliderValue] = React.useState(40)
const handleChange = (value) => {
setSliderValue(value)
}
return (
<HStack space="lg">
<Text size="md">$0</Text>
<Tooltip
placement={"top"}
trigger={(triggerProps) =>