Skip to content
Drivn
6 min read

Drivn vs shadcn/ui — Slider Compared

Drivn Slider vs shadcn/ui — zero-runtime pointer-events handler with sm/md/lg size prop versus the Radix UI primitive that ships multi-thumb range support.

Most slider decisions come down to one question asked early: will this control ever need two thumbs? shadcn/ui builds its Slider on @radix-ui/react-slider, so the value is always an array and the same component renders one thumb or several, with arrow-key, Home/End, and PageUp/PageDown stepping handled by the primitive. The price is a Radix package in your lockfile and an API that wraps even a single volume level in brackets — value={[50]} paired with onValueChange.

Drivn's Slider commits to the single-value case. It is one pure React + Tailwind client file of roughly 140 lines that imports only React and cn(). A pointerdown on the track measures it with getBoundingClientRect(), maps the pointer position to a ratio, snaps it to step, and reports a plain number through onChange. Sizes come from a typed 'sm' | 'md' | 'lg' union backed by styles.sizes, orientation flips between horizontal and vertical, and a hidden <input type="range"> carries name and the forwarded ref into native forms.

So the split is breadth versus ownership. shadcn/ui covers range pickers and full keyboard stepping out of the box; Drivn hands you a flat number API and a drag handler short enough to read, and extend, in one sitting. The sections below compare dependencies, API shape, the size token, and where Radix still earns its place. The Drivn CLI writes the file to @/components/ui/slider.tsx.

Side-by-side comparison

FeatureDrivnshadcn/ui
Underlying implementationSingle client component, pointer events on the trackWraps @radix-ui/react-slider primitive (Slider.Root/Track/Range/Thumb)
Runtime UI dependenciescn() utility only — zero npm packages@radix-ui/react-slider
Public API shapeFlat — <Slider value={n} onChange={fn} />Compound — <Slider value={[n]} onValueChange={fn} />
Value typenumber (single thumb)number[] (multi-thumb capable)
Multi-thumb rangeNot supported — one thumbBuilt-in via array value
Built-in size prop'sm' | 'md' | 'lg' (sm/md/lg track + thumb)No size prop — adjust via className
Orientation'horizontal' | 'vertical''horizontal' | 'vertical'
Keyboard navigationHidden range input (read-only) — pointer/touch onlyFull arrow-key support via Radix
Form integrationHidden <input type="range" name={name}>Hidden input via Radix
Client componentYes — 'use client'Yes — 'use client'
LicenseMITMIT
Copy-paste install

Zero Radix dependency, one file you own

shadcn/ui's Slider is a thin styling layer on top of @radix-ui/react-slider. The primitive does the work — track sizing, thumb positioning, drag gestures, keyboard navigation, ARIA attributes — and the shadcn file maps Radix sub-components to Tailwind classes. The trade-off is one extra package in your package.json, one extra entry in your lockfile, and one extra peer dependency moving on its own release cadence.

Drivn's Slider has no Radix. The file imports React and the local cn() utility, declares a styles object with base/track/range/thumb/horizontal/vertical/sizes/disabled keys, and renders a root div wrapping the track, range fill, and thumb, plus a hidden range input. Drag handling is a handlePointerDown callback that captures pointer move/up listeners on document, reads getBoundingClientRect() off a trackRef, computes the ratio, runs it through snap(val, min, step), and calls onChange. The whole component is about 140 lines and ships with the Drivn CLI directly into your project.

1// packages/drivn/src/registry/components/slider.ts — verbatim excerpt
2function snap(val: number, min: number, step: number) {
3 return Math.round((val - min) / step) * step + min
4}
5
6function handlePointerDown(e: React.PointerEvent) {
7 if (disabled) return
8 e.preventDefault()
9 resolve(e.clientX, e.clientY)
10 const onMove = (ev: PointerEvent) =>
11 resolve(ev.clientX, ev.clientY)
12 const onUp = () => {
13 document.removeEventListener('pointermove', onMove)
14 document.removeEventListener('pointerup', onUp)
15 }
16 document.addEventListener('pointermove', onMove)
17 document.addEventListener('pointerup', onUp)
18}

Flat API instead of compound sub-components

The shadcn Slider follows the Radix compound pattern: <Slider value={[50]} onValueChange={setValue} max={100} step={1} />, where the value is an array — even for a single thumb — because the same primitive renders multi-thumb range sliders. The wrapper component composes Slider.Root, Slider.Track, Slider.Range, and one Slider.Thumb per array entry.

Drivn's API is flat. <Slider value={50} onChange={setValue} max={100} step={1} /> — a single number value, a callback that receives a number, no array wrapping. The component renders one thumb, one range fill, one track, and that is the contract. If you need a low/high range slider with two thumbs, Drivn does not have it and shadcn does. If you only ever need one thumb (a volume knob, a brightness setting, a single price ceiling, an opacity dial), Drivn's flat API is one fewer destructure per render. Use the Drivn CLI to drop the file into @/components/ui/slider.tsx.

1"use client"
2
3import { useState } from "react"
4import { Slider } from "@/components/ui/slider"
5
6export default function VolumePanel() {
7 const [volume, setVolume] = useState(50)
8
9 return (
10 <Slider
11 value={volume}
12 onChange={setVolume}
13 max={100}
14 />
15 )
16}

A built-in size token, not a className guess

shadcn/ui's Slider has no size prop. Track height and thumb diameter are written into the component file as fixed Tailwind classes, so a compact slider in a toolbar and a large one in a settings hero mean either editing the shared file or layering overrides through className at every call site.

Drivn types size as keyof typeof styles.sizes, which autocompletes to 'sm' | 'md' | 'lg' and rejects anything else at compile time. Each entry holds three classes: track sets the height of a horizontal track, thumb sets the thumb diameter, and vTrack sets the track width when orientation="vertical", so one prop scales both axes. In pixels that is a 4px track with a 12px thumb for sm, 6px with 16px for the default md, and 8px with 20px for lg. Because the scale lives in one object, adding an xl step or thickening every slider in the app is a single edit in the file you own. Pair sm with a Label in dense forms and keep lg for a standalone control such as a volume panel.

1// Drivn styles.sizes — verbatim from the registry
2sizes: {
3 sm: { track: 'h-1', thumb: 'w-3 h-3', vTrack: 'w-1' },
4 md: { track: 'h-1.5', thumb: 'w-4 h-4', vTrack: 'w-1.5' },
5 lg: { track: 'h-2', thumb: 'w-5 h-5', vTrack: 'w-2' },
6},
7
8// Usage
9<Slider defaultValue={40} size="sm" />
10<Slider defaultValue={50} size="md" />
11<Slider defaultValue={60} size="lg" />

Where Radix wins: keyboard and multi-thumb

There are two situations where the shadcn/ui Slider is the right pick. The first is keyboard navigation. Radix's primitive wires arrow keys to step the value, Home/End to jump to min/max, and PageUp/PageDown to step by a larger increment, all out of the box. Drivn renders a hidden <input type="range"> for form submission with tabIndex={-1} and readOnly — the input ships the value, but the focus and key handling live on the visual thumb only as ARIA hints. If your slider is the primary control on a page where keyboard-only users will land, Radix's wiring is worth the extra package.

The second is multi-thumb range sliders. A price filter that takes a low and a high, an audio editor with start/end markers, a graphics tool with a histogram range — shadcn's array-valued API renders two thumbs and tracks them independently from one call. Drivn's single-number API does not. For one-thumb controls (volume, brightness, opacity, single-threshold filters), Drivn is leaner; for two-thumb controls, reach for shadcn or compose two Drivn Sliders side-by-side with linked state.

1// shadcn/ui multi-thumb range — for reference
2"use client"
3import { useState } from "react"
4import { Slider } from "@/components/ui/slider"
5
6export function PriceRange() {
7 const [range, setRange] = useState([20, 80])
8
9 return (
10 <Slider
11 value={range}
12 onValueChange={setRange}
13 min={0}
14 max={100}
15 />
16 )
17}
Get started

Install Drivn in one command

Copy the source into your project and own every line. Zero runtime dependencies, pure React + Tailwind.

npx drivn@latest create

Requires Node 18+. Works with npm, pnpm, and yarn.

Enjoying Drivn?
Star the repo on GitHub to follow new component releases.
Star →

Frequently asked questions

No. The component imports React and the local cn() utility — nothing else. Drag handling reads pointer events off a trackRef directly, value snapping is a four-line helper inside the file, and ARIA attributes are spread onto the thumb div. The entire file is around 140 lines and ships with the Drivn CLI as @/components/ui/slider.tsx. No @radix-ui/react-slider, no peer dependency, no extra entry in package.json.

Not from one component instance. Drivn's Slider takes a single number value and renders one thumb, by design. If you need a low/high range slider, you have two options: reach for shadcn/ui where the Radix primitive supports an array value out of the box, or compose two Drivn Sliders with linked state — one controlling the low end, one the high, and onChange handlers that clamp each against the other.

Pass the size prop. The union is "sm" | "md" | "lg" and maps to the styles.sizes object in the component file: sm is a 4-pixel track with a 12-pixel thumb, md (the default) is 6/16, lg is 8/20. The same mapping covers vertical orientation — vTrack keys set the track width when orientation="vertical". For finer control, pass a className; cn() merges with the size classes using later-class precedence so your utility wins.

Partially. The component renders a hidden <input type="range"> with the current value, min, max, and step for form submission, but it is read-only and tabIndex={-1}, so arrow keys on the visual thumb do not step the value the way Radix does. If keyboard-only navigation is critical for the page — for example, a settings dialog where the slider is the primary control — the shadcn/ui Slider built on @radix-ui/react-slider is the safer choice. Pointer and touch input on Drivn work end-to-end.

Yes. The file starts with 'use client' because it uses useState for the uncontrolled value, useRef for the track measurement, and document-level pointermove/pointerup listeners for the drag gesture. Rendering it inside a server component means the parent stays server-side and the Slider hydrates on its own. If you need a server-rendered placeholder before hydration, pair it with a Skeleton via the Skeleton component or render a static thumb inside a Suspense fallback.

Yes. Pass a name prop and the component renders a hidden <input type="range" name={name} value={current}> alongside the visual thumb. The input is read-only and not focusable, but standard form submission picks it up — useful with the Form, Label, and form-state patterns from the Drivn docs. For controlled forms with react-hook-form, wire value and onChange to the field's register or Controller as usual; the name prop becomes optional.