Skip to content

Add scroll-lifecycle callbacks (or built-in snap-back) + root ref/prop-spread to support controlled usage #72

Description

@Nandan1996

Problem statement

When the picker is used in controlled mode the parent component may reject an out-of-range value (e.g. user scrolls to “12 AM” while min is 12 PM).
Typical pattern:

  1. In onValueChange we set a temporary state so the wheel shows the rejected item.
  2. Immediately revert to the last valid value.

While inertia is still running the picker’s internal scrollRef.current is reset during that round-trip.
The next wheel delta is therefore measured against a new baseline and the picker emits the same rejected value again, causing AM ↔ PM flicker and repeated callbacks.


What would fix it

  1. Expose scroll-lifecycle hooks

    <WheelPicker
      
      onScrollStart={() => {/* gesture started */}}
      onScrollEnd={()   => {/* safe to revert */}}
    />

    We can then delay the “reject & revert” until onScrollEnd, eliminating the loop.

    OR

    Accept a boolean from onValueChange:

    onValueChange?: (value: string) => boolean  // return false → library animates snap-back
  2. Quality-of-life API additions (zero breakage)

    • Forward a ref to the root <div data-rwp>
    • Spread unknown props onto that root (data-attributes, test-ids, etc.)

These small changes let consumers cleanly reject values, observe gesture boundaries, and imperatively access the component—no DOM queries or debounce hacks required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions