Cómo funciona
The wheel's position is one number in rows, --_p, written to the root's style on animation frames; every word works out its distance d from it in CSS. In the arc shape the start of a word is carried by −d × the step angle round a hub to the right of the words (the step is the row height divided by the radius), so the list curves like the edge of a dial, and the word itself tilts by only 45% of that angle, so long words do not lean into the next row; in the drum shape it turns round an axis behind the words with rotateX. Opacity falls with |d| to nothing just past the rows in view, and blur grows past the centre row. A drag follows the finger one row per row height with growing resistance past the ends. On release the speed over the last 90ms projects where a coast would stop; the wheel then approaches that whole row exponentially (time constant 0.26s), so it arrives quickly and settles softly on the detent. Scrolling turns it directly and settles when scrolling pauses. A press on a word turns the wheel to it, and with multiple ticks it. React renders only when the centred word changes, which also ticks a small accent mark in the centre band.
Úsalo para
- Choosing from a list that is long but well known: treatments, genres, cuisines, times, quantities.
- Mobile sheets and booking flows, where a thumb flick is faster than scrolling a long list.
- Filters where several words can be ticked without leaving the wheel.
Busca otra opción cuando
- Lists people need to search or compare: use a select or a multi-select with search.
- Fewer than five options: show them all as chips or radios.
Uso
import { useState } from 'react'
import { WheelPicker } from './WheelPicker.jsx'
const treatments = ['Massage', 'Facial', 'Sauna', 'Steam room', 'Hot stones', 'Reflexology']
export function TreatmentPicker() {
const [picked, setPicked] = useState(['Facial'])
return <WheelPicker label="Treatments" items={treatments} multiple value={picked} onChange={setPicked} />
}
export function TimePicker({ slots }) {
const [time, setTime] = useState(slots[0])
return <WheelPicker label="Start time" items={slots} value={time} onChange={setTime} shape="drum" />
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
items | (string | { value, label, disabled? })[] | — | The words in order. Plain strings are their own value. |
multiple | boolean | false | Several choices: pressing a word, or Space on the centred one, ticks it. Off, the word the wheel rests on is the value. |
value / defaultValue / onChange | value | value[] / … / (next, changed) => void | - / first item or [] / - | Single choice: the value of the chosen word, set when the wheel comes to rest; setting it from outside turns the wheel there. Multiple: the ticked values, in list order. |
onActiveChange | (value, index) => void | — | Fires each time another word passes the centre, while the wheel is still moving. |
defaultActive | number | 0 | With multiple, the index of the word centred at first. |
shape | 'arc' | 'drum' | 'arc' | arc: the words follow the edge of a large dial whose hub is to their right, each tilted along the curve. drum: they wrap round a cylinder and turn in depth. |
rows / itemHeight / radius | number / number / number | 5 / 36 / by shape | Rows in view, the height of one row in px, and the dial's or drum's radius in px (6.5 or 2.9 rows by default). |
blur | boolean | true | Blurs words with their distance from the centre. Off, they only fade. |
label | string | — | Accessible name of the list. |
disabled | boolean | false | Fades the wheel and ignores input. |
...rest | HTMLAttributes | — | Other attributes go to the root <div>. |
Accesibilidad
- The wheel is a listbox (aria-multiselectable with multiple) named by label; every word is an option with aria-selected, and aria-activedescendant follows the centred word.
- Up and Down move one word, PageUp and PageDown a wheel's height, Home and End the ends; with multiple, Space or Enter ticks the centred word. Focus lights the centre band with a ring.
- Ticked words show a filled check as well as darker text, so the choice is not carried by colour alone.
- Touch: touch-action keeps sideways page gestures but gives vertical drags to the wheel; any word in view can be pressed directly.
- Reduced motion drops the coast: the wheel follows a drag and then jumps to the nearest word, and keys and presses move it at once.
Movimiento
Coast after a flick: exponential approach with a 0.26s time constant to the projected row. Keys and presses: 0.10 to 0.15s time constant. Release without speed or end of scrolling: 0.10 to 0.12s. Centre mark: a 160ms tick on every word that passes. Tick: background fills over --ds-duration-fast and the circle pops on --ds-ease-spring.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
WheelPicker.jsxwheel-picker.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.







