diff --git a/packages/block-editor/src/components/block-draggable/use-scroll-when-dragging.js b/packages/block-editor/src/components/block-draggable/use-scroll-when-dragging.js index aa66c27503cf9..a01db4927b652 100644 --- a/packages/block-editor/src/components/block-draggable/use-scroll-when-dragging.js +++ b/packages/block-editor/src/components/block-draggable/use-scroll-when-dragging.js @@ -78,7 +78,10 @@ export default function useScrollWhenDragging() { SCROLL_INACTIVE_DISTANCE_PX, 0 ); - const distancePercentage = dragDistance / moveableDistance; + const distancePercentage = + moveableDistance === 0 || dragDistance === 0 + ? 0 + : dragDistance / moveableDistance; velocityY.current = VELOCITY_MULTIPLIER * distancePercentage; } else if ( event.clientY < offsetDragStartPosition ) { // User is dragging upwards. @@ -92,7 +95,10 @@ export default function useScrollWhenDragging() { SCROLL_INACTIVE_DISTANCE_PX, 0 ); - const distancePercentage = dragDistance / moveableDistance; + const distancePercentage = + moveableDistance === 0 || dragDistance === 0 + ? 0 + : dragDistance / moveableDistance; velocityY.current = -VELOCITY_MULTIPLIER * distancePercentage; } else { velocityY.current = 0;