← Components

Selection and input

Picker wheel

An iOS-style scroll wheel: scroll, drag or use arrow keys; rows curve away from the centre like a drum around a fixed highlight pill.

Examples and variants

Hours and minutes

Two wheels side by side.

1
2
3
4
5
6
7
8
9
10
11
12
00
05
10
15
20
25
30
35
40
45
50
55

Alarm at 9:30

Example
function TimeWheels() {
  const hours = Array.from({ length: 12 }, (_, i) => String(i + 1))
  const minutes = Array.from({ length: 12 }, (_, i) => String(i * 5).padStart(2, "0"))
  const [h, setH] = useState("9")
  const [m, setM] = useState("30")
  return (
    <div className="flex flex-col items-center gap-3">
      <div className="flex gap-2">
        <PickerWheel label="Hour" options={hours} value={h} onValueChange={setH} />
        <PickerWheel label="Minute" options={minutes} value={m} onValueChange={setM} />
      </div>
      <p className="text-sm text-muted-foreground tabular-nums">
        Alarm at {h}:{m}
      </p>
    </div>
  )
}

Spec drawing

Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.

Install

With the CLI

The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/picker-wheel.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install cn
  2. Copy this file to the same paths in your project. Imports use the @/ alias for your project root.

    • components/ui/picker-wheel.tsxpicker-wheel
      components/ui/picker-wheel.tsx
      "use client"
      
      import * as React from "react"
      import { cn } from "cn"
      import { tokenMs } from "@/lib/motion/token-ms"
      
      /*
        Picker wheel: an iOS-style scroll wheel. Scroll, drag or use the arrow keys;
        items curve away from the centre like a drum, and the middle row sits in a
        fixed highlight pill. The value changes when the wheel settles.
      */
      function PickerWheel({
        options,
        value,
        onValueChange,
        label,
        className,
      }: {
        options: string[]
        value: string
        onValueChange: (value: string) => void
        label: string
        className?: string
      }) {
        const ref = React.useRef<HTMLDivElement>(null)
        const id = React.useId()
        const settle = React.useRef(0)
        const index = Math.max(0, options.indexOf(value))
      
        const paint = React.useCallback(() => {
          const node = ref.current
          if (!node) return
          const rowHeight = node.clientHeight / 5
          const center = node.scrollTop + node.clientHeight / 2
          node.querySelectorAll<HTMLElement>("[role=option]").forEach((row) => {
            const mid = row.offsetTop + row.offsetHeight / 2
            const d = Math.max(-2.5, Math.min(2.5, (mid - center) / rowHeight))
            row.style.setProperty("--d", String(d))
          })
        }, [])
      
        React.useLayoutEffect(() => {
          const node = ref.current
          if (!node) return
          const align = () => {
            const row = node.querySelectorAll<HTMLElement>("[role=option]")[index]
            if (row) {
              const top = row.offsetTop - node.clientHeight / 2 + row.offsetHeight / 2
              if (Math.abs(node.scrollTop - top) > 1) node.scrollTop = top
            }
            paint()
          }
          align()
          const observer = new ResizeObserver(align)
          observer.observe(node)
          return () => observer.disconnect()
        }, [index, paint])
      
        function onScroll() {
          const node = ref.current
          if (!node) return
          requestAnimationFrame(paint)
          window.clearTimeout(settle.current)
          settle.current = window.setTimeout(() => {
            const rowHeight = node.clientHeight / 5
            const next = Math.round(node.scrollTop / rowHeight)
            const option = options[Math.max(0, Math.min(options.length - 1, next))]
            if (option !== value) onValueChange(option)
          }, tokenMs("--duration-quick"))
        }
      
        function step(delta: number) {
          const next = options[Math.max(0, Math.min(options.length - 1, index + delta))]
          const node = ref.current
          const row = node?.querySelectorAll<HTMLElement>("[role=option]")[options.indexOf(next)]
          if (node && row) node.scrollTo({ top: row.offsetTop - node.clientHeight / 2 + row.offsetHeight / 2, behavior: "smooth" })
          onValueChange(next)
        }
      
        return (
          <div data-slot="picker-wheel" className={cn("picker-wheel relative h-(--picker-height) w-(--picker-width) overflow-hidden rounded-(--picker-corner) bg-(--picker-container)", className)}>
            <span aria-hidden className="pointer-events-none absolute inset-x-2 top-1/2 h-(--picker-row) -translate-y-1/2 rounded-(--picker-pill-corner) bg-(--picker-pill)" />
            <div
              ref={ref}
              role="listbox"
              tabIndex={0}
              aria-label={label}
              aria-activedescendant={`${id}-${index}`}
              onScroll={onScroll}
              onKeyDown={(event) => {
                if (event.key === "ArrowDown") step(1)
                else if (event.key === "ArrowUp") step(-1)
                else if (event.key === "Home") step(-options.length)
                else if (event.key === "End") step(options.length)
                else return
                event.preventDefault()
              }}
              className="picker-scroll relative h-full snap-y snap-mandatory overflow-y-scroll overscroll-contain py-[calc(var(--picker-row)*2)] outline-none [scrollbar-width:none] focus-visible:shadow-(--focus-ring) [&::-webkit-scrollbar]:hidden"
            >
              {options.map((option, i) => (
                <div
                  key={option}
                  id={`${id}-${i}`}
                  role="option"
                  aria-selected={i === index}
                  onClick={() => step(i - index)}
                  className="picker-row flex h-(--picker-row) snap-center items-center justify-center text-sm tabular-nums"
                >
                  {option}
                </div>
              ))}
            </div>
          </div>
        )
      }
      
      export { PickerWheel }
      

Imports

What the examples on this page import:

Imports
import { Bubble, BubbleReactions } from "@/components/ui/bubble"
import { PickerWheel } from "@/components/ui/picker-wheel"
import { ReactionPicker } from "@/components/ui/reaction-picker"
import { RollingNumber } from "@/components/ui/rolling-number"
import { Slider } from "@/components/ui/slider"
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { ThemeToggle } from "@/components/ui/theme-toggle"

Anatomy

  1. 1Drum · --picker-height, --picker-width, --picker-container, --picker-corner.
  2. 2Row · --picker-row; curves by --picker-curve under --picker-perspective.
  3. 3Pill · --picker-pill, --picker-pill-corner, fixed in the middle.

Props

PropTypeDefaultDescription
optionsstring[]—Values in order.
value / onValueChangestring—Changes when the wheel settles.
labelstring—Accessible name.

Tokens

Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.

TokenPoints toLightDark
--picker-rowvar(--size-row)40pxsame
--picker-heightcalc(var(--picker-row) * 5)calc(var(--picker-row) * 5)same
--picker-widthcalc(var(--space-24) + var(--space-8))calc(var(--space-24) + var(--space-8))same
--picker-containervar(--surface-container-low)oklch(0.985 0.004 95)oklch(0.17 0 0)
--picker-cornervar(--shape-lg)22pxsame
--picker-pillvar(--surface-container-lowest)oklch(1 0 0)oklch(0.14 0 0)
--picker-pill-cornervar(--shape-md)14pxsame
--picker-perspectivecalc(var(--picker-row) * 10)calc(var(--picker-row) * 10)same
--picker-curve-22deg-22degsame

Motion

TriggerWhat happensTokens
ScrollNative snap; rows tilt and fade by distance from the centre.--picker-curve

Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.

Accessibility

  • A listbox with the current option active; arrows, Home and End move.

Usage

Do

  • Use for short ordered lists on touch screens.

Don’t

  • Don't use for long lists (use Select or Combobox).

Code

components/ui/picker-wheel.tsx
"use client"

import * as React from "react"
import { cn } from "cn"
import { tokenMs } from "@/lib/motion/token-ms"

/*
  Picker wheel: an iOS-style scroll wheel. Scroll, drag or use the arrow keys;
  items curve away from the centre like a drum, and the middle row sits in a
  fixed highlight pill. The value changes when the wheel settles.
*/
function PickerWheel({
  options,
  value,
  onValueChange,
  label,
  className,
}: {
  options: string[]
  value: string
  onValueChange: (value: string) => void
  label: string
  className?: string
}) {
  const ref = React.useRef<HTMLDivElement>(null)
  const id = React.useId()
  const settle = React.useRef(0)
  const index = Math.max(0, options.indexOf(value))

  const paint = React.useCallback(() => {
    const node = ref.current
    if (!node) return
    const rowHeight = node.clientHeight / 5
    const center = node.scrollTop + node.clientHeight / 2
    node.querySelectorAll<HTMLElement>("[role=option]").forEach((row) => {
      const mid = row.offsetTop + row.offsetHeight / 2
      const d = Math.max(-2.5, Math.min(2.5, (mid - center) / rowHeight))
      row.style.setProperty("--d", String(d))
    })
  }, [])

  React.useLayoutEffect(() => {
    const node = ref.current
    if (!node) return
    const align = () => {
      const row = node.querySelectorAll<HTMLElement>("[role=option]")[index]
      if (row) {
        const top = row.offsetTop - node.clientHeight / 2 + row.offsetHeight / 2
        if (Math.abs(node.scrollTop - top) > 1) node.scrollTop = top
      }
      paint()
    }
    align()
    const observer = new ResizeObserver(align)
    observer.observe(node)
    return () => observer.disconnect()
  }, [index, paint])

  function onScroll() {
    const node = ref.current
    if (!node) return
    requestAnimationFrame(paint)
    window.clearTimeout(settle.current)
    settle.current = window.setTimeout(() => {
      const rowHeight = node.clientHeight / 5
      const next = Math.round(node.scrollTop / rowHeight)
      const option = options[Math.max(0, Math.min(options.length - 1, next))]
      if (option !== value) onValueChange(option)
    }, tokenMs("--duration-quick"))
  }

  function step(delta: number) {
    const next = options[Math.max(0, Math.min(options.length - 1, index + delta))]
    const node = ref.current
    const row = node?.querySelectorAll<HTMLElement>("[role=option]")[options.indexOf(next)]
    if (node && row) node.scrollTo({ top: row.offsetTop - node.clientHeight / 2 + row.offsetHeight / 2, behavior: "smooth" })
    onValueChange(next)
  }

  return (
    <div data-slot="picker-wheel" className={cn("picker-wheel relative h-(--picker-height) w-(--picker-width) overflow-hidden rounded-(--picker-corner) bg-(--picker-container)", className)}>
      <span aria-hidden className="pointer-events-none absolute inset-x-2 top-1/2 h-(--picker-row) -translate-y-1/2 rounded-(--picker-pill-corner) bg-(--picker-pill)" />
      <div
        ref={ref}
        role="listbox"
        tabIndex={0}
        aria-label={label}
        aria-activedescendant={`${id}-${index}`}
        onScroll={onScroll}
        onKeyDown={(event) => {
          if (event.key === "ArrowDown") step(1)
          else if (event.key === "ArrowUp") step(-1)
          else if (event.key === "Home") step(-options.length)
          else if (event.key === "End") step(options.length)
          else return
          event.preventDefault()
        }}
        className="picker-scroll relative h-full snap-y snap-mandatory overflow-y-scroll overscroll-contain py-[calc(var(--picker-row)*2)] outline-none [scrollbar-width:none] focus-visible:shadow-(--focus-ring) [&::-webkit-scrollbar]:hidden"
      >
        {options.map((option, i) => (
          <div
            key={option}
            id={`${id}-${i}`}
            role="option"
            aria-selected={i === index}
            onClick={() => step(i - index)}
            className="picker-row flex h-(--picker-row) snap-center items-center justify-center text-sm tabular-nums"
          >
            {option}
          </div>
        ))}
      </div>
    </div>
  )
}

export { PickerWheel }