Skip to content
Browse documentation

Drums you can fling: each column is a real cylinder that decays onto a row, with a lens in full colour over the middle.

Used forAlarm and timer appsDate pickersForms with short listsMobile web settings

Install with the shadcn CLI

$ npx shadcn@latest add @hairline/wheel-picker

Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/wheel-picker.json. More

Templates

Need the whole page?

65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.

Where it’s used

  • Alarm and timer apps

    Choose hours and minutes on drums.

  • Date pickers

    Day, month and year columns that never allow an impossible date.

  • Forms with short lists

    Quantities, sizes or durations picked by turning a wheel.

  • Mobile web settings

    A phone-style picker where a select would look out of place.

What it handles for you

Web pickers are usually a select, or a scrolling list with snap points that stutter. These are drums you can fling, like the ones on a phone.

Instead of wiring upa native selecta scroll-snap lista time pickera date pickermomentum scrollinghaptic ticks
  1. Real drums

    Options tip away toward the rim as they leave the middle, and a lens band in full colour sits over the middle row.

  2. Flings that land

    The release speed is projected forward and the wheel decays onto a row instead of snapping.

  3. The value commits at rest

    onValueChange is called once the wheel stops on a new option, not while it turns.

  4. Options that can’t be chosen

    Disabled options are dimmed and passed over, so a date picker can rule out days that do not exist.

  5. Loops and units

    Columns can loop, like minutes. A unit beside the lens morphs with the value, from “1 hour” to “2 hours”.

  6. Keyboard and screen readers

    Each wheel is a spinbutton: arrows step, Page Up and Down jump five, and Home and End go to the ends.

Overview

Web pickers are usually a select or a scrolling list with snap points that stutter. These are drums. Each column is a cylinder of faces turned by one transform, so the options tip away toward the rim as they leave the middle. The middle row is a second copy of the drum clipped to the band in full colour, so a number crossing the band's edge is half muted, half bright, like glass over the wheel. Drag and let go: the release speed is projected forward and the wheel decays onto a row instead of snapping, with a tick under the finger on phones that can vibrate. Wheels that don't loop stretch past their ends. The value is committed when the wheel rests, the unit beside the lens morphs with it, and options that can't be chosen are dimmed and passed over.

States

drag
The drum follows the pointer one row per row height. Past the ends of a wheel that doesn't loop it stretches with resistance, up to about one and a half rows.
fling
Release velocity from the last 90ms is projected 0.3s ahead and rounded to a row; the wheel decays onto it exponentially (τ 300ms, or 120ms for a short nudge), so it lands without a separate snap.
wheel and keys
A mouse notch or an arrow key moves one row (τ 110ms), Page Up and Down five. Trackpad scrolling turns the drum freely and settles 120ms after it goes quiet.
rest
The value is committed and announced as the wheel comes to rest. A unit beside the lens morphs with it, e.g. hour to hours. A dimmed option turns on to the nearest one that can be chosen.
set from outside
When the value changes from your code (a day that no longer exists in February), the wheel turns to it the shorter way round.

Usage

usage.tsx
import { Wheel, WheelPicker } from "@/components/wheel-picker";const hours = Array.from({ length: 12 }, (_, i) => i + 1);const minutes = Array.from({ length: 60 }, (_, i) => ({ value: i, label: String(i).padStart(2, "0") }));<WheelPicker aria-label="Alarm time">  <Wheel label="Hour" options={hours} value={hour} onValueChange={setHour} loop align="end" />  <Wheel label="Minute" options={minutes} value={minute} onValueChange={setMinute} loop align="start" />  <Wheel label="AM or PM" options={["AM", "PM"]} value={period} onValueChange={setPeriod} align="start" /></WheelPicker>

Works with

A date that can't be wrong

Days past the end of the month are disabled, so the wheel dims them and turns past them; when the month changes under a day that no longer exists, set the day and the wheel turns to it.

example.tsx
"use client";import * as React from "react";import { Wheel, WheelPicker } from "@/components/wheel-picker";const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];export function BirthdayField({ onChange }: { onChange: (date: Date) => void }) {  const [month, setMonth] = React.useState(0);  const [day, setDay] = React.useState(1);  const [year, setYear] = React.useState(1995);  const max = new Date(year, month + 1, 0).getDate();  const days = Array.from({ length: 31 }, (_, i) => ({ value: i + 1, disabled: i + 1 > max }));  React.useEffect(() => {    if (day > max) setDay(max);    else onChange(new Date(year, month, day));  }, [day, month, year, max, onChange]);  return (    <WheelPicker aria-label="Date of birth">      <Wheel label="Month" options={MONTHS.map((label, value) => ({ value, label }))} value={month} onValueChange={setMonth} loop align="start" />      <Wheel label="Day" options={days} value={Math.min(day, max)} onValueChange={setDay} loop />      <Wheel label="Year" options={Array.from({ length: 90 }, (_, i) => 1940 + i)} value={year} onValueChange={setYear} align="end" />    </WheelPicker>  );}

Props

WheelPicker itemHeight= 36
number
Row height in px (28–56). The drum's radius, the band and the text size follow from it.
WheelPicker haptics= true
boolean
A 3ms vibration per row while a finger turns a wheel, on phones that support it.
options
(T | { value: T; label?: string; disabled?: boolean })[]
Strings, numbers or objects. Disabled options are dimmed and the wheel turns past them.
value / defaultValue
T
Controlled or uncontrolled. A controlled change turns the wheel to the new option.
onValueChange
(value: T) => void
Called once the wheel comes to rest on a new option, not while it turns.
loop= false
boolean
Turn past the end back to the start, like minutes or months.
label
string
What the wheel sets, for screen readers: "Hours".
unit
string | (value: T) => string
Fixed beside the lens, e.g. "min", or a function for "1 hour" / "2 hours". It morphs when the value changes.
align= "center"
"start" | "center" | "end"
Where the options sit in their column.

Accessibility and motion

  • Each wheel is a spinbutton with aria-valuetext (the option and its unit). Arrow keys step, Page Up and Down jump five, Home and End go to the ends.
  • A tap on a row above or below the lens turns it to the middle; the row is found from the drum's angle, not the flat offset, so rows near the rim land correctly.
  • Every wheel has 18 faces whatever its length: only faces turning round the back are relabelled, so 60 minutes or 100 years cost the same. Turning writes two transforms a frame and renders nothing through React.
  • The drum leaves a hole under the lens through its mask, so the lens copy is the only text there; mouse wheels over the picker turn it instead of scrolling the page.
  • Reduced motion turns the wheel straight to the row instead of decaying onto it; dragging still follows the pointer.

Requirements

React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

The CLI also installs Text morph.

Source

'use client';/* ───────────────────────────────────────────────────────── * WHEEL PICKER: drums you can fling * *   drum      every column is a real cylinder: options sit on *             its faces and tip away into the dark as they *             leave the middle, one transform a frame *   lens      the middle row is a separate copy of the drum, *             clipped to the band, in full colour; a letter *             crossing the band's edge is half one, half the *             other, like glass over the wheel *   fling     drag and let go: the release speed is projected *             forward and the wheel decays onto a row, with a *             tick on phones for each row it passes; past the *             ends of a wheel that doesn't loop it stretches *   settle    the value is committed once the wheel rests, and *             a unit beside the lens morphs with it (1 hour, *             2 hours). Options that can't be chosen are dimmed *             and the wheel turns on past them * * Each wheel is a spinbutton: arrows step, Page Up and Down * jump five, Home and End go to the ends; a mouse notch moves * one row and taps on a row bring it to the middle. * ───────────────────────────────────────────────────────── */import * as React from 'react';import { TextMorph } from './text-morph';import { useInteractionReducedMotion } from './ui-interaction-motion';import { SLOTS, STEP, useWheelDrum } from './use-wheel-drum';export type WheelValue = string | number;export type WheelOption<T extends WheelValue = WheelValue> = T | { value: T; label?: string; disabled?: boolean };export interface WheelPickerProps extends React.HTMLAttributes<HTMLDivElement> {  /** Row height in px; the drum's radius follows from it. */  itemHeight?: number;  /** Ticks on phones that can vibrate, one per row. */  haptics?: boolean;  children: React.ReactNode;}export interface WheelProps<T extends WheelValue = WheelValue> {  options: readonly WheelOption<T>[];  value?: NoInfer<T>;  defaultValue?: NoInfer<T>;  onValueChange?: (value: NoInfer<T>) => void;  /** Turn past the end back to the start, like minutes. */  loop?: boolean;  /** What the wheel sets, for screen readers: "Hours". */  label: string;  /** Fixed beside the lens: "min", or a function for "1 hour" / "2 hours". */  unit?: string | ((value: NoInfer<T>) => string);  /** Where the options sit in their column. */  align?: 'start' | 'center' | 'end';  className?: string;  style?: React.CSSProperties;}const Ctx = React.createContext({ itemHeight: 36, haptics: true });const PERSPECTIVE = 1000;const valueOf = <T extends WheelValue>(o: WheelOption<T>) => (typeof o === 'object' ? o.value : o);const labelOf = <T extends WheelValue>(o: WheelOption<T>) => (typeof o === 'object' ? (o.label ?? String(o.value)) : String(o));const offOf = <T extends WheelValue>(o: WheelOption<T>) => typeof o === 'object' && Boolean(o.disabled);export function WheelPicker({ itemHeight = 36, haptics = true, className = '', style, children, ...props }: WheelPickerProps) {  const H = Math.max(28, Math.min(56, itemHeight));  const radius = H / (2 * Math.tan((STEP / 2) * (Math.PI / 180)));  const ctx = React.useMemo(() => ({ itemHeight: H, haptics }), [H, haptics]);  return (    <Ctx.Provider value={ctx}>      <div role="group" className={`relative flex w-full select-none justify-center px-2 ${className}`} style={{ height: Math.round(radius * 2), ...style }} {...props}>        <div aria-hidden="true" className="pointer-events-none absolute inset-x-0 top-1/2 -translate-y-1/2 rounded-[11px] bg-muted" style={{ height: H }} />        {children}      </div>    </Ctx.Provider>  );}export function Wheel<T extends WheelValue = WheelValue>({  options,  value,  defaultValue,  onValueChange,  loop = false,  label,  unit,  align = 'center',  className = '',  style,}: WheelProps<T>) {  const { itemHeight: H, haptics } = React.useContext(Ctx);  const reduced = useInteractionReducedMotion();  const count = options.length;  const indexOf = (v: T | undefined) => Math.max(0, options.findIndex((o) => valueOf(o) === v));  const [own, setOwn] = React.useState<T | undefined>(defaultValue ?? (count ? valueOf(options[0]) : undefined));  const current = value !== undefined ? value : own;  const index = indexOf(current);  const optionsRef = React.useRef(options);  const report = React.useRef(onValueChange);  React.useLayoutEffect(() => {    optionsRef.current = options;    report.current = onValueChange;  });  const controlled = value !== undefined;  const committed = React.useRef(index);  const drum = useWheelDrum(index, {    count,    loop,    itemHeight: H,    reduced,    haptics,    label: (i) => labelOf(optionsRef.current[i]),    disabled: (i) => offOf(optionsRef.current[i]),    onRest: (i) => {      if (i === committed.current) return;      committed.current = i;      const next = valueOf(optionsRef.current[i]);      if (!controlled) setOwn(next);      report.current?.(next);    },  });  // The value changed from outside (another wheel clamped it, or the app set it): turn to it.  const first = React.useRef(true);  React.useEffect(() => {    if (first.current) { first.current = false; return; }    if (index === committed.current) return;    committed.current = index;    drum.turnTo(index, !reduced);    // eslint-disable-next-line react-hooks/exhaustive-deps  }, [index]);  // Labels or disabled options changed: relabel the faces in place.  const labels = options.map((o) => `${labelOf(o)}${offOf(o) ? '·' : ''}`).join('|');  React.useEffect(() => { drum.repaint(); }, [labels]); // eslint-disable-line react-hooks/exhaustive-deps  // Faces are labelled once here; the drum relabels them directly as it turns.  const [faceText] = React.useState(() =>    Array.from({ length: SLOTS }, (_, k) => {      const i = k + SLOTS * Math.round((index - k) / SLOTS);      const real = loop ? ((i % count) + count) % count : i;      return count && (loop || (i >= 0 && i < count)) ? labelOf(options[real]) : '';    }),  );  const unitOf = (v: T) => (typeof unit === 'function' ? unit(v) : (unit ?? ''));  const unitText = current !== undefined && unit ? unitOf(current) : '';  const widest = unit ? options.map((o) => unitOf(valueOf(o))).reduce((a, b) => (b.length > a.length ? b : a), '') : '';  const onKeyDown = (e: React.KeyboardEvent) => {    const moves: Record<string, number> = { ArrowUp: -1, ArrowDown: 1, PageUp: -5, PageDown: 5 };    if (e.key in moves) {      e.preventDefault();      drum.nudge(moves[e.key]);    } else if (e.key === 'Home' || e.key === 'End') {      e.preventDefault();      const to = e.key === 'Home' ? 0 : count - 1;      drum.turnTo(to, !reduced);    }  };  const justify = align === 'start' ? 'justify-start' : align === 'end' ? 'justify-end' : 'justify-center';  const faceClass = `absolute inset-x-0 flex items-center whitespace-nowrap px-2.5 tabular-nums [backface-visibility:hidden] data-[off]:opacity-35 ${justify}`;  const face = (k: number) => ({ top: -H / 2, height: H, transform: `rotateX(${-k * STEP}deg) translateZ(${drum.radius}px)` });  const edge = `calc(50% - ${H / 2}px)`, edge2 = `calc(50% + ${H / 2}px)`;  // The drum fades toward its rim and leaves a hole where the lens copy sits.  const mask = `linear-gradient(to bottom, transparent 8%, #000 36%, #000 ${edge}, transparent ${edge}, transparent ${edge2}, #000 ${edge2}, #000 64%, transparent 92%)`;  // The first frame's rotation; after that the drum writes its own transform, so React must never touch it.  const [current3d] = React.useState(() => ({ transformStyle: 'preserve-3d' as const, transform: `translateZ(${-drum.radius}px) rotateX(${index * STEP}deg)` }));  return (    <div      ref={(el) => drum.attachColumn(el)}      role="spinbutton"      tabIndex={0}      aria-label={label}      aria-valuenow={index}      aria-valuemin={0}      aria-valuemax={Math.max(0, count - 1)}      aria-valuetext={`${count ? labelOf(options[index]) : ''}${unitText ? ` ${unitText}` : ''}`}      onKeyDown={onKeyDown}      className={`group relative flex h-full min-w-0 flex-1 cursor-grab touch-none items-center outline-none active:cursor-grabbing ${className}`}      style={style}    >      <div className="relative h-full min-w-0 flex-1 tracking-[-0.01em]" style={{ fontSize: Math.round(H * 0.56) }}>        <div aria-hidden="true" className="absolute inset-0 text-muted-foreground" style={{ perspective: PERSPECTIVE, maskImage: mask, WebkitMaskImage: mask }}>          <div ref={(el) => drum.attachDrum(el)} className="absolute inset-x-0 top-1/2 h-0 will-change-transform" style={current3d}>            {faceText.map((t, k) => (              <span key={k} ref={(el) => drum.attachFace(k, el)} className={faceClass} style={face(k)}>{t}</span>            ))}          </div>        </div>        <div          aria-hidden="true"          className="absolute inset-x-0 top-1/2 -translate-y-1/2 overflow-hidden rounded-[11px] text-foreground group-focus-visible:ring-2 group-focus-visible:ring-ring/50"          style={{ height: H, perspective: PERSPECTIVE }}        >          <div ref={(el) => drum.attachLens(el)} className="absolute inset-x-0 top-1/2 h-0 will-change-transform" style={current3d}>            {faceText.map((t, k) => (              <span key={k} ref={(el) => drum.attachLensFace(k, el)} className={faceClass} style={face(k)}>{t}</span>            ))}          </div>        </div>      </div>      {unit && (        <span aria-hidden="true" className="relative grid shrink-0 pr-2.5 text-[14px] font-medium text-foreground">          <span className="invisible col-start-1 row-start-1 whitespace-nowrap">{widest}</span>          <span className="col-start-1 row-start-1 whitespace-nowrap"><TextMorph animateWidth={false}>{unitText}</TextMorph></span>        </span>      )}    </div>  );}

Registry item: /r/wheel-picker.json