Skip to content
Klarhimmel UI

Slider

npx shadcn add @klarhimmel/slider

Examples

  • Basic

  • States

  • Form

DetailsAbout, usage, props and more

A single-value slider on the native range input.

When to use

  • Use for

    A rough value on a range where the position says more than the number.

  • Not for

    An exact figure. Use Input type number. A choice among named options. Use Radio group.

  • Pairs with

    Label and a visible output next to it.

Preview

2
slider.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Slider } from '@/components/klarhimmel/ui/slider';

export default function Example() {
  return (
    <Theme theme="brand">
      <div className="flex flex-col gap-1">
        <label htmlFor="guests" className="text-kh-small font-medium">Guests</label>
        <Slider id="guests" min={1} max={8} defaultValue={2} />
      </div>
    </Theme>
  );
}

Import

Import

import { Slider } from '@/components/klarhimmel/ui/slider';
Files
slider.tsx, in components/klarhimmel/ui/. With it: theme, utils.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

Props

PropTypeDefaultDescription
aria-labelstring-Required unless a <label htmlFor> names it.
minnumber0The range and its steps.
maxnumber100The range and its steps.
stepnumber1The range and its steps.
native attributesInputHTMLAttributes-Every native attribute of the element passes through, className included.

Accessibility

KeyDoes
Left / DownDecreases by one step
Right / UpIncreases by one step
Page Down / Page UpMoves in larger steps
Home / EndMinimum or maximum

Native range input: the keys and the slider role are the browser's. Always show the current number next to it.

Accessibility