# Wheel Picker

A cylindrical drum picker with flick momentum, a bouncing detent, keyboard selection, and optional glass.

Page: https://sui.draco.dev/docs/components/wheel-picker

WheelPicker selects one value from an ordered list. Touch, mouse and pen drag the drum directly, rubber-banding past either end; a flick coasts on with momentum and settles on a row with a small bounce. A mouse wheel or trackpad spins it continuously and snaps once it goes idle. The centre row is a crisp copy of the drum clipped to the selection band, so labels sharpen exactly as they cross it, without a duplicate accessible list.

### Example: wheel-picker-demo

```tsx
"use client";

import { FieldLabel } from "@workspace/ui/components/field";
import { Switch } from "@workspace/ui/components/switch";
import { WheelPicker } from "@workspace/ui/components/wheel-picker";
import { useId, useState } from "react";
import type { ExampleProps } from "../types";

export default function Example({ locale }: ExampleProps) {
  const zh = locale === "zh-CN";
  const [value, setValue] = useState("30");
  const [sound, setSound] = useState(false);
  const soundId = useId();
  return (
    <div className="flex flex-col items-center gap-6">
      <p className="text-sm" aria-live="polite">
        {zh ? `时长：${value} 分钟` : `Duration: ${value} minutes`}
      </p>
      <WheelPicker
        aria-label={zh ? "时长（分钟）" : "Duration in minutes"}
        options={["5", "10", "15", "20", "30", "45", "60", "90"]}
        value={value}
        onValueChange={setValue}
        feedback={sound ? "sound" : false}
      />
      <div className="flex items-center gap-2">
        <Switch id={soundId} checked={sound} onCheckedChange={setSound} />
        <FieldLabel htmlFor={soundId}>
          {zh ? "刻度音" : "Tick sound"}
        </FieldLabel>
      </div>
    </div>
  );
}
```

## Installation

```bash
npx shadcn@latest add draco-china/sui/wheel-picker
```

With pnpm, Yarn or Bun, use `pnpm dlx`, `yarn dlx` or `bunx --bun` in place of `npx`, and `pnpm add`, `yarn add` or `bun add` in place of `npm install`.

Load SUI's base styles as described in [Installation](/docs/installation). Default light/dark colors are included; other palettes are optional.

## Usage

```tsx
import { WheelPicker } from "@workspace/ui/components/wheel-picker";

<WheelPicker
  aria-label="Duration in minutes"
  options={["15", "30", "45", "60"]}
  defaultValue="30"
  name="duration_minutes"
/>;
```

Options can be strings or `{ label, value }` objects. Values must be unique. Use `value` and `onValueChange` for controlled selection. The parent owns the selected value and can reject a request; uncontrolled selection uses `defaultValue`. An absent or missing value displays the first option. Changing the available options clamps the displayed selection without emitting a user change.

## Compose columns

Combine independently labelled wheels inside a named group. Application code owns date validity, dependent columns, formatting, and persistence.

### Example: wheel-picker-composed

```tsx
"use client";

import { WheelPicker } from "@workspace/ui/components/wheel-picker";
import { useState } from "react";
import type { ExampleProps } from "../types";

const hours = Array.from({ length: 24 }, (_, index) =>
  String(index).padStart(2, "0"),
);
const minutes = Array.from({ length: 12 }, (_, index) =>
  String(index * 5).padStart(2, "0"),
);

export default function Example({ locale }: ExampleProps) {
  const zh = locale === "zh-CN";
  const [hour, setHour] = useState("09");
  const [minute, setMinute] = useState("30");
  return (
    <div className="flex max-w-full flex-col items-center gap-6">
      <p className="text-sm tabular-nums" aria-live="polite">
        {zh ? "提醒时间" : "Reminder time"} · {hour}:{minute}
      </p>
      <fieldset
        aria-label={zh ? "提醒时间" : "Reminder time"}
        className="flex max-w-full items-center gap-2"
      >
        <WheelPicker
          className="w-24"
          aria-label={zh ? "小时" : "Hours"}
          options={hours}
          value={hour}
          onValueChange={setHour}
        />
        <span aria-hidden="true" className="text-sm">
          :
        </span>
        <WheelPicker
          className="w-24"
          aria-label={zh ? "分钟" : "Minutes"}
          options={minutes}
          value={minute}
          onValueChange={setMinute}
        />
      </fieldset>
    </div>
  );
}
```

## Keyboard and accessibility

The wheel is a single focusable listbox with `aria-activedescendant` and selected options. Supply a localized `aria-label` or `aria-labelledby`. Arrow Up/Down selects the previous/next value; Home/End reaches the boundaries, and Page Up/Down moves by one visible page. Selection stops at either end.

With reduced motion, the same list and controls remain available as a flat list that moves in place, without cylinder rotation or animated settling. `disabled` and empty options remove the wheel from the Tab sequence and prevent changes. `name` submits the selected value through a hidden input; native form reset restores an uncontrolled default. Tick sound follows `feedback` and is off by default; set `feedback="sound"` or enable sound on `FeedbackProvider`. Like the beUI reference, it uses a locally synthesized 16ms mechanical click whenever the nearest row changes while dragging, spinning, or coasting; settling on the same row does not play it again. Keyboard and direct selection also tick once. Audio is prepared at the start of a user gesture, shares one context and buffer across columns, and cuts the previous tick tail during rapid movement. Initial rendering, form reset, and external value updates stay silent. Audio failures never block selection.

### Example: wheel-picker-states

```tsx
import { WheelPicker } from "@workspace/ui/components/wheel-picker";
import type { ExampleProps } from "../types";

export default function Example({ locale }: ExampleProps) {
  const zh = locale === "zh-CN";
  return (
    <div className="flex max-w-full flex-wrap justify-center gap-6">
      <WheelPicker
        disabled
        aria-label={zh ? "已停用的时长" : "Disabled duration"}
        options={["15", "30", "45"]}
        defaultValue="30"
        className="w-28"
      />
      <WheelPicker
        aria-label={zh ? "空选项" : "Empty options"}
        options={[]}
        className="w-28"
      />
    </div>
  );
}
```

## Material

The default is a solid working control using SUI semantic colors and 14px text. `glass` or `frosted` applies the shared material to its frame; individual rows stay ordinary. Keyboard focus remains visible. The drum owns its gestures, so dragging or spinning it never scrolls the page behind it.

## API reference

| Prop | Type | Default / behavior |
| --- | --- | --- |
| `options` | `readonly WheelPickerOption[]` | Required; unique values. |
| `value`, `defaultValue` | `string` | Controlled value or initial uncontrolled value. |
| `onValueChange` | `(value: string) => void` | Called for a user selection. |
| `visibleCount` | `number` | `7`; normalized to an odd count from 3 to 11. The wheel is as tall as the drum's projection; reduced motion gives every row a full slot. |
| `itemHeight` | `number` | `36` pixels; minimum 24. |
| `disabled` | `boolean` | `false`. |
| `feedback` | `FeedbackOption` | Follows `FeedbackProvider`; selection haptic and tick per row crossed. |
| `name` | `string` | Optional form field name. |
| `glass`, `frosted` | `boolean \| GlassConfig`, `boolean` | Ordinary by default. |
| Other props | Native div props | Includes labels, `ref`, `className`, `style`, and event handlers. |

Exports `WheelPicker`, `WheelPickerProps`, and `WheelPickerOption`. The interaction references [beUI Wheel Picker](https://beui.dev/components/motion/wheel-picker); this SUI implementation drives the drum with Motion.
