Skip to content

Slider

Download .md

A slider picks a value, or a range with two thumbs, by dragging along a track, such as the part of a song to use as a preview.

  • Use it when the rough position matters more than the exact number: a preview window, a volume.
  • Always show the value as text next to it, such as “0:30–1:00 dari 3:20”.
  • When the number has to be exact, such as a price or a percentage in a contract, use an Input.
React

Potong preview

0:30–1:00 dari 3:20

Vue

Potong preview

0:30–1:00 dari 3:20

1234
  1. 1Track
  2. 2Selected range
  3. 3Thumb
  4. 4Value
Part Style
Track 6px (h-1.5), rounded-full, bg-muted
Range bg-primary
Thumb 16px (size-4), rounded-full, a primary border on background

With two thumbs, they never pass each other.

React Vue Flutter Type Default Use
value, onValueChange v-model ShadSlider initialValue, onChanged number[] / number none The value, or the start and end of a range.
min, max, step same min, max, divisions number 0, 100, 1 The range and the step.
getAriaLabel get-aria-label Semantics label function none Names each thumb, such as “Awal” and “Akhir”.
getAriaValueText get-aria-value-text semanticFormatterCallback function the number What screen readers say, such as “1:05”.

shadcn_ui has one thumb; for a range in Flutter, use Material’s RangeSlider inside SosialokaTheme.material.

import { useState } from "react"
import { Slider } from "@/components/ui/slider"
const time = (seconds: number) => `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`
export default function SliderDemo() {
const [range, setRange] = useState([30, 60])
return (
<div className="flex w-full max-w-sm flex-col gap-3">
<div className="flex items-baseline justify-between text-sm">
<p id="preview-label" className="font-medium">
Potong preview
</p>
<p className="text-muted-foreground tabular-nums">
{time(range[0])}–{time(range[1])} dari 3:20
</p>
</div>
<Slider
aria-labelledby="preview-label"
value={range}
onValueChange={(value) => setRange(value as number[])}
max={200}
getAriaLabel={(index) => (index === 0 ? "Awal" : "Akhir")}
getAriaValueText={(_, value) => time(value)}
/>
</div>
)
}
Terminal window
npx shadcn@latest add https://design.sosialoka.tech/r/react/slider.json
  • Each thumb is a slider with a name and a spoken value, such as “Awal, 0:30”.
  • Arrow keys move one step, Page Up and Page Down ten, Home and End to the ends.
  • The value also shows as text, so nobody has to drag to read it.