Skip to content

Commit 1a2c87e

Browse files
prayaClaudéric Demers
authored and
Claudéric Demers
committed
fix: overflow bug while dragging an item upwards in a grid
1 parent 0512151 commit 1a2c87e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/SortableContainer/index.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -774,31 +774,45 @@ export default function sortableContainer(
774774
y: 10,
775775
};
776776

777-
if (translate.y >= this.maxTranslate.y - this.height / 2) {
777+
const {
778+
scrollTop,
779+
scrollLeft,
780+
scrollHeight,
781+
scrollWidth,
782+
clientHeight,
783+
clientWidth,
784+
} = this.scrollContainer;
785+
786+
const isTop = scrollTop === 0;
787+
const isBottom = scrollHeight - scrollTop - clientHeight === 0;
788+
const isLeft = scrollLeft === 0;
789+
const isRight = scrollWidth - scrollLeft - clientWidth === 0;
790+
791+
if (translate.y >= this.maxTranslate.y - this.height / 2 && !isBottom) {
778792
// Scroll Down
779793
direction.y = 1;
780794
speed.y =
781795
acceleration.y *
782796
Math.abs(
783797
(this.maxTranslate.y - this.height / 2 - translate.y) / this.height,
784798
);
785-
} else if (translate.x >= this.maxTranslate.x - this.width / 2) {
799+
} else if (translate.x >= this.maxTranslate.x - this.width / 2 && !isRight) {
786800
// Scroll Right
787801
direction.x = 1;
788802
speed.x =
789803
acceleration.x *
790804
Math.abs(
791805
(this.maxTranslate.x - this.width / 2 - translate.x) / this.width,
792806
);
793-
} else if (translate.y <= this.minTranslate.y + this.height / 2) {
807+
} else if (translate.y <= this.minTranslate.y + this.height / 2 && !isTop) {
794808
// Scroll Up
795809
direction.y = -1;
796810
speed.y =
797811
acceleration.y *
798812
Math.abs(
799813
(translate.y - this.height / 2 - this.minTranslate.y) / this.height,
800814
);
801-
} else if (translate.x <= this.minTranslate.x + this.width / 2) {
815+
} else if (translate.x <= this.minTranslate.x + this.width / 2 && !isLeft) {
802816
// Scroll Left
803817
direction.x = -1;
804818
speed.x =

0 commit comments

Comments
 (0)