suiss/ui · Component
Wheel Picker
A scrolling, 3D-curved wheel of options, like the iOS picker, for choosing values such as dates and times.
Wheel Picker is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
WheelPicker is the frame: it draws the highlighted selection band across the middle and lays out one or more WheelPickerColumn wheels side by side. Each column is a scrolling list of WheelPickerItem options that snap to the center, and rows curve away and fade as they move from the middle.
A column selects the item that comes to rest in the center after scrolling, or the item that's clicked. Use a wheel picker for touch-friendly choices from ordered lists, especially several related columns such as day, hour and minute. For a compact dropdown, use Select.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
-
Add the
cnhelper. -
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a WheelPicker:
Examples
Disabled items
Set disabled on items that can't be chosen, here booked time slots. Scrolling skips past them to the nearest enabled item, and the keyboard and clicks skip them too.
Date time
Combines controlled day, hour and minute columns into a date and time picker. Each column takes value and onValueChange.
Accessibility
- Each column has the
listboxrole and is focusable; name it witharia-label. Items areoptionelements witharia-selected, and the column points to the selected item witharia-activedescendant. - With a column focused, the up and down arrow keys move to the previous or next enabled item,
Page UpandPage Downmove by five, andHomeandEndjump to the first and last enabled items. - Disabled items set
aria-disabledand ignore clicks. - When reduced motion is preferred, the column scrolls to new values without smooth scrolling.
API Reference
WheelPicker
The frame that holds the columns and draws the selection band.
Also accepts the props of React.ComponentProps<"div">.
Row height comes from --wheel-picker-item-height (--spacing(8) by default), set on WheelPicker; the column shows about seven rows. The curve is driven by scroll-driven animations where ViewTimeline is supported, and by a scroll handler elsewhere.
WheelPickerColumn
A scrolling, snapping wheel that holds one selected value.
| Prop | Type | Default |
|---|---|---|
value | string | - |
defaultValue | string | - |
onValueChange | (value: string) => void | - |
Also accepts the props of React.ComponentProps<"div">.
Each column manages its own value. Use defaultValue for an uncontrolled column, or value with onValueChange to control it. onValueChange fires when the column settles on a new value: the item that comes to rest in the center after scrolling, or the item that's clicked.
WheelPickerItem
A single option in a column.
| Prop | Type | Default |
|---|---|---|
value | string | Required |
disabled | boolean | false |
Also accepts the props of React.ComponentProps<"div">.
Give every item a string value that is unique in its column; its children are the visible label.
Each part sets a data-slot, such as wheel-picker-column, for styling. Items also set data-value, data-selected and data-disabled.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
WheelPicker lays out one or more WheelPickerColumn components side by side behind a shared highlight band. Each column is a snapping ScrollView; items above and below the center are scaled, moved and faded with React Native Animated interpolations to look like a rotating wheel.
Use it for times, dates and other values picked from a short, ordered list, often in a sheet or popover.
Installation
The CLI also adds what it builds on: Text.
- Install the following dependencies:
-
Add the pieces it builds on: Text.
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/wheel-picker.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Text.
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/wheel-picker.tsx:
- Update the import paths to match your project setup.
-
Add the pieces it builds on: Text.
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/wheel-picker.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Examples
Disabled items
A time list where booked slots are disabled. Disabled items are skipped: if the wheel stops on one, it moves to the nearest enabled item.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Date time
Controlled day, hour and minute columns combined into one value. The value is set when scrolling settles or when an item is pressed.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Accessibility
- Each column has the
adjustablerole and announces the selected item's label as its value. - VoiceOver and TalkBack users swipe up or down to move to the next or previous enabled item.
- Give each column an
accessibilityLabel, such asHourorMinute. - The highlight band is hidden from screen readers.
API Reference
WheelPicker
Root row of columns with the selection highlight.
Also accepts the props of React.ComponentProps<typeof WheelPickerPrimitive.Root>.
Set itemHeight to change the row height. A selection haptic plays when the value changes, if a haptics adapter is provided through the haptics context.
WheelPickerColumn
Snapping scroll column that holds one value.
Also accepts the props of React.ComponentProps<typeof WheelPickerPrimitive.Column>.
Give each column a defaultValue, or value with onValueChange. Combine several columns for compound values such as day, hour and minute, and use className on columns and items to control width and alignment.
WheelPickerItem
Single row in a column.
Also accepts the props of React.ComponentProps<typeof WheelPickerPrimitive.Item>.
Give each item a unique value. Plain string or number children are wrapped in single-line Text.
WheelPicker
Root row of columns with the selection highlight.
| Parameter | Type | Default |
|---|---|---|
spacing | CGFloat | 0 |
content | () -> Content | - |
WheelPickerColumn
Snapping scroll column that holds one value.
| Parameter | Type | Default |
|---|---|---|
selection | Binding<Value> | - |
alignment | HorizontalAlignment | .center |
content | () -> Content | - |
WheelPickerItem
Single row in a column.
| Parameter | Type | Default |
|---|---|---|
value | Value | - |
label | () -> Label | - |
_Â title | LocalizedStringKey | - |
verbatim | String | - |
Overloads: init(value:label:), init(_:value:), init(verbatim:value:).
WheelPickerColumnScope.WheelPickerItem
| Parameter | Type | Default |
|---|---|---|
value | String | - |
enabled | Boolean | true |
content | @Composable () -> Unit | - |
text | String | - |
Overloads: WheelPickerItem(value, content), WheelPickerItem(value, text).
WheelPicker
Root row of columns with the selection highlight.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
horizontalArrangement | Arrangement.Horizontal | Arrangement.Center |
content | @Composable RowScope.() -> Unit | - |
WheelPickerColumn
Snapping scroll column that holds one value.
| Parameter | Type | Default |
|---|---|---|
value | String? | - |
onValueChange | (String) -> Unit | - |
modifier | Modifier | Modifier |
label | String? | null |
horizontalAlignment | Alignment.Horizontal | Alignment.CenterHorizontally |
itemPadding | Dp | 12.dp |
content | WheelPickerColumnScope.() -> Unit | - |