Skip to content

Commit

Permalink
update snap points boundaries check to also deal with top and left di…
Browse files Browse the repository at this point in the history
…rections (#217)
  • Loading branch information
erisleci committed Jan 20, 2024
1 parent ad9e00c commit 0423945
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/use-snap-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,13 @@ export function useSnapPoints({
? activeSnapPointOffset - draggedDistance
: activeSnapPointOffset + draggedDistance;

// Don't do anything if we exceed the last(highest) snap point
if (newYValue < snapPointsOffset[snapPointsOffset.length - 1]) return;
// Don't do anything if we exceed the last(biggest) snap point
if ((direction === 'bottom' || direction === 'right') && newValue < snapPointsOffset[snapPointsOffset.length - 1]) {
return;
}
if ((direction === 'top' || direction === 'left') && newValue > snapPointsOffset[snapPointsOffset.length - 1]) {
return;
}

set(drawerRef.current, {
transform: isVertical(direction) ? `translate3d(0, ${newValue}px, 0)` : `translate3d(${newValue}px, 0, 0)`,
Expand Down

0 comments on commit 0423945

Please sign in to comment.