Wheel Picker
iOS-style scroll wheels to pick a time, a height, a weight or any value from a short list, by swipe, scroll, click or keys.
c2-wheel-picker is the picker of iOS and of fitness apps: each wheel is a column of rows that scrolls and snaps, and the row in the band across the middle is its value. It suits short lists picked with a thumb, such as a time, a height, a weight or a size.
Import
import '@c2n/components/wheel-picker'Usage
Wheels
columns lists the wheels, as a JSON attribute or a property. Each has options (strings, or { value, label?, disabled? }), a label that names it for screen readers, and an optional suffix shown after it (“ft”, “kg”) and read with its value. For a single wheel, options alone is enough: a JSON array, or a ;-separated list.
Value
value holds one value per wheel; as an attribute, the values are separated by ; (value="5;10"). A wheel without a value starts on its first enabled row, so the picker always has a value.
When the user turns a wheel, the row it settles on becomes its value, and input then change fire. A swipe, the mouse wheel and a click on a row all turn it. A disabled row is skipped: a wheel that settles on one moves on to the nearest enabled row. Setting value turns the wheels without firing events.
In a form
Under a name, the form receives the values joined by ;. Inside a c2-form-field, the field’s label names the picker and its hint describes it.
Look
How many rows show is CSS: --c2-wheel-picker--visible-rows (5 by default; an odd number keeps the band in the middle) and --c2-wheel-picker__row--height. The band, the faded rows and the picked row each have their own variables.
Keyboard
Each wheel is a spin button with one tab stop. Up and Down step a row, Page Up and Page Down step five, and Home and End go to the ends. Disabled rows are skipped.