Slider
Slider with thoughtful defaults, semantic styling, and editable source.
Make it yours.
Install the editable source and its dependencies into your React + Tailwind project.
Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/slider.jsonUse it
Scroll horizontally for long lines
"use client";
import {Slider} from '@/components/jez-ui/ui/slider';
export default function Example(){
return <><div className="grid min-w-0 w-full max-w-sm gap-8"><div className="flex items-end justify-between"><h3 className="text-3xl">Set the tone.</h3><span className="text-xs text-muted-foreground">Ambient radio</span></div><div className="flex h-20 min-w-0 items-center justify-center gap-1 sm:gap-1.5" aria-hidden="true">{Array.from({length:32},(_,i)=><span key={i} className="w-1.5 rounded-full bg-primary" style={{height:12+Math.abs(Math.sin(i*.8))*55}}/>)}</div><Slider label="Volume" defaultValue={[65]}/><div className="flex justify-between text-xs text-muted-foreground"><span>A little quieter</span><span>Turn it up</span></div></div></>;
}Props & types
Scroll horizontally for long lines
React.ComponentProps<typeof Primitive.Root> & { label?: string }Source
View 2 source files
registry/ui/slider.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
import { Slider as Primitive } from "radix-ui";
export function Slider({
className,
label = "Value",
...props
}: React.ComponentProps<typeof Primitive.Root> & { label?: string }) {
return (
<Primitive.Root
defaultValue={[50]}
className={cn(
"relative flex h-8 w-full touch-none select-none items-center",
className,
)}
{...props}
>
<Primitive.Track className="relative h-1.5 grow rounded-full bg-muted">
<Primitive.Range className="absolute h-full rounded-full bg-primary" />
</Primitive.Track>
{(props.value ?? props.defaultValue ?? [50]).map((_, i) => (
<Primitive.Thumb
key={i}
aria-label={`${label}${i ? " " + (i + 1) : ""}`}
className="block size-5 rounded-full border-2 border-primary bg-background"
/>
))}
</Primitive.Root>
);
}
registry/ui/utils.ts
Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
return twMerge(clsx(values));
}
Dependencies
radix-ui@1.6.7 · clsx@2.1.1 · tailwind-merge@3.5.0
Accessibility & behaviour
Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.
Read the accessibility and performance guide →