GooseUI

Components

Rotary Dial

New

RotaryDial puts any items on a ring: letters, numbers or short labels. Turn it by dragging around the centre, with the mouse wheel or the arrow keys. On release the ring snaps to the nearest item, and the item under the pointer at the top is the value.

Preview

Drag the ring, scroll over it or focus it and press the arrows.

MonthJune

Installation

npx shadcn@latest add @gooseui/rotary-dial
pnpm dlx shadcn@latest add @gooseui/rotary-dial
yarn dlx shadcn@latest add @gooseui/rotary-dial
bunx --bun shadcn@latest add @gooseui/rotary-dial

Usage

import { RotaryDial } from "@/components/ui/rotary-dial"

const sizes = ["XS", "S", "M", "L", "XL", "XXL"]

export default function Example() {
  const [index, setIndex] = useState(2)

  return (
    <RotaryDial
      items={sizes}
      value={index}
      onValueChange={setIndex}
      labels={{ label: "Size" }}
    />
  )
}

Examples

Caesar cipher

outerItems adds a fixed ring. Each letter of the outer ring sits above its replacement on the inner one, so the shift is just the angle of the wheel.

shift3A → D
Plain text
MEET ME AT THE OLD BRIDGE
Encoded
PHHW PH DW WKH ROG EULGJH
const alphabet = Array.from({ length: 26 }, (_, i) =>
  String.fromCharCode(65 + i),
)

const [shift, setShift] = useState(3)

<RotaryDial
  items={alphabet}
  outerItems={alphabet}
  value={shift}
  onValueChange={setShift}
  labels={{
    label: "Cipher wheel",
    valueText: (to, i) => `Shift ${i}, A becomes ${to}`,
  }}
  renderCenter={(to, i) => (
    <>
      <span className="font-mono text-2xl font-bold">{i}</span>
      <span className="font-mono text-xs">A → {to}</span>
    </>
  )}
/>

Combination lock

Several small dials with digits. The value is an index, so it is easy to compare with a code.

0
0
0

Find the code. Hint: the digits add up to 13.

const digits = Array.from({ length: 10 }, (_, i) => String(i))
const [code, setCode] = useState([0, 0, 0])

{code.map((digit, slot) => (
  <RotaryDial
    key={slot}
    items={digits}
    value={digit}
    size={140}
    onValueChange={(d) =>
      setCode((prev) => prev.map((v, i) => (i === slot ? d : v)))
    }
    labels={{ label: `Digit ${slot + 1}` }}
  />
))}

Custom centre

renderCenter replaces the hub content. Short labels stay on the ring, the full name goes in the middle and in aria-valuetext.

const short = ["Jan", "Feb", "Mar", /* … */ "Dec"]
const full = ["January", "February", "March", /* … */ "December"]

<RotaryDial
  items={short}
  defaultValue={5}
  labels={{ label: "Month", valueText: (_, i) => full[i] }}
  renderCenter={(_, i) => (
    <span className="text-lg font-semibold">{full[i]}</span>
  )}
/>

Props

PropTypeDefaultDescription
itemsreadonly string[]-Items on the rotating ring, clockwise
valuenumber-Index of the item under the pointer (controlled)
defaultValuenumber0Initial index when uncontrolled
onValueChange(index: number) => void-Called with the new index while turning and on release
outerItemsreadonly string[]-Fixed outer ring to read against the rotating one
sizenumber260Size in px
renderCenter(item: string, index: number) => ReactNode-Content of the hub. Shows the current item by default
pageStepnumber5How many items PageUp and PageDown skip
disabledbooleanfalseTurns off all interaction
labels{ label?: string; valueText?: (item, index) => string }{ label: "Dial" }aria-label of the dial and the announced value text
classNamestring-Additional CSS classes
--rotary-dial-easing<easing-function>linear(…)CSS variable. Easing of snapping and stepping. Default is a damped spring in linear() with ~8% overshoot, cubic-bezier(0.34, 1.56, 0.64, 1) where linear() is unsupported
--rotary-dial-duration<time>520msCSS variable. Duration of the turn. Under prefers-reduced-motion it becomes 120ms ease-out with no bounce

Keyboard

KeyAction
← → ↑ ↓One item clockwise or counter-clockwise
PageUp / PageDownSkip pageStep items
HomeFirst item
EndLast item