shadcn.io is not affiliated with official shadcn/ui
Slider examples · Styled
With Tooltip Slider for React
A Progress slider with a bubble above the thumb that shows its percentage.
The value rides along with the thumb. A small bubble above the track is placed at the same percentage as the value, so it follows the thumb as it moves. Use it where people watch the number while they drag.
Preview
Installation
FAQ
Is this a Tooltip component?
No. The bubble is a div in a relative pt-6 wrapper, absolute -top-2 with bg-primary and text-primary-foreground. It is always visible and aria-hidden, since the slider already announces its value.
How does the bubble follow the thumb?
Its inline start is set to the value as a percent, and -translate-x-1/2 centers it on that point. It moves on every step, while you drag or use the keys.
How does the readout follow the thumb?
The value lives in state, starting at 45, and goes back to the slider as value. The bubble prints it with a % sign.
onValueChange receives the new value, and the handler stores it as an array.
What happens to the bubble at 0% and 100%?
The bubble is placed by the raw percent, so near the ends half of it hangs past the track, and it can sit slightly off the thumb. Clamp the position if that matters in your layout.
Related
- Synced with Input Field SliderA slider and a number field that share
- Colored SliderA Success Rate slider whose fill and
- With Live Preview SliderA Border Radius slider from 0 to 50px
- Simple SliderA single-thumb slider with no label or
- With Reset Button SliderAn Adjustment slider with a Reset button
- Large/Thick SliderA Volume slider with a thicker track and