Mastering the Ant Design Mobile Picker: API, Gestures, Performance & Accessibility

This article walks through the design and implementation of Ant Design Mobile's Picker component, covering its API, gesture handling, animation techniques, performance optimizations, and accessibility improvements for screen‑reader users, while sharing practical code examples and visual diagrams.

Alipay Experience Technology
Alipay Experience Technology
Alipay Experience Technology
Mastering the Ant Design Mobile Picker: API, Gestures, Performance & Accessibility

API Design

We start by defining the essential Picker properties: value, onConfirm, and columns. The columns prop is a two‑dimensional array where the first level represents each wheel and the second level contains the options for that wheel. The component is built on top of a Popup container, with header buttons, a wheel list rendered from columns, and a gradient mask that highlights the currently selected item.

API design diagram
API design diagram

Gestures & Animation

The Picker supports two interaction modes: direct tap and drag. Drag handling is implemented with the use-gesture library’s useDrag hook, which tracks the pointer’s x/y movement and updates a translateY value in real time. When the drag ends, the slider should spring back to its original position. While a simple CSS transition can animate this return, it cannot be applied during active dragging, so we conditionally add a grabbing class to disable the transition while dragging.

For more precise control we switch to a JavaScript‑based animation using react-spring. A spring is created with useSpring (initial y = 0) and bound to an animated.div. The drag handler updates the spring’s y value directly while dragging and resets it to 0 on release, preserving the current velocity and avoiding abrupt jumps.

useDrag example
useDrag example
react-spring animation
react-spring animation

Performance

Using React DevTools Profiler we discovered that every wheel re‑renders when any wheel is dragged, causing frame drops. The solution is to memoize the Wheel component and provide a custom prop‑comparison function, ensuring only the wheel whose data changed re‑renders. After this optimization, profiling shows a dramatic reduction in renders and no more dropped frames.

Profiler result
Profiler result

Accessibility

To make the Picker usable for screen‑reader users, the visual wheel is hidden from assistive technologies and a transparent overlay is added. This overlay displays the currently selected option as text and provides two invisible buttons for “previous” and “next” actions. The overlay is fully transparent but remains focusable, allowing blind users to navigate the Picker with a screen reader.

Accessibility overlay
Accessibility overlay

Finally, the talk thanks the Ant Design Mobile community: over six months the project received 325 pull requests, 460 commits, and 416 issues from 50 contributors, illustrating the power of open‑source collaboration.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceaccessibilityReactAnt Design MobilePicker Component
Alipay Experience Technology
Written by

Alipay Experience Technology

Exploring ultimate user experience and best engineering practices

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.