emilkowalski / vaul

An unstyled drawer component for React.
https://vaul.emilkowal.ski
MIT License
5.98k stars 199 forks source link

feature request: with snap points, make high-velocity behavior optional #333

Closed artemis-prime closed 2 weeks ago

artemis-prime commented 5 months ago

Currently, if the drawer is swiped quickly, it will always pass snap points and close / open fully. There are many use cases where this is undesirable (snap points have specific meanings or other state effects and should always be passed-through). This would be a very easy change. We could have an alwaysSnapToNextPoint optional prop or some such thing



// use-snap-points.ts:152

    if (!alwaysSnapToNextPoint && velocity > 2 && !hasDraggedUp) {
      if (dismissible) closeDrawer();
      else snapToPoint(snapPointsOffset[0]); // snap to initial point
      return;
    }

    if (!alwaysSnapToNextPoint && velocity > 2 && hasDraggedUp && snapPointsOffset && snapPoints) {
      snapToPoint(snapPointsOffset[snapPoints.length - 1] as number);
      return;
    }
emilkowalski commented 2 weeks ago

Added snapToSequentialPoint prop in #415