Skip to content

Commit 1beb239

Browse files
authored
Fix a bug in pausing invisible elements (#321)
- Add the test detects the bug - FIx the bug in setting the correct flag
1 parent 24c324b commit 1beb239

2 files changed

Lines changed: 64 additions & 8 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright (c) Jalal Maskoun.
3+
*
4+
* This source code is licensed under the AGPL3.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
let elmBox;
9+
let startingPointX;
10+
// let startingPointY;
11+
12+
// const stepsX = 0;
13+
// const stepsY = 0;
14+
15+
context(
16+
"Testing not all elements transformed when dragging still inside viewport",
17+
() => {
18+
before(() => {
19+
cy.visit("http://localhost:3001/extended");
20+
});
21+
22+
it("Getting element (#1)", { scrollBehavior: false }, () => {
23+
cy.get("#1-extended").then((elm) => {
24+
elmBox = elm[0].getBoundingClientRect();
25+
startingPointX = elmBox.x + elmBox.width / 2;
26+
// startingPointY = elmBox.y + elmBox.height / 2;
27+
cy.get("#1-extended").trigger("mousedown", {
28+
button: 0,
29+
});
30+
});
31+
});
32+
33+
it("Transforms (#1-extended) to the right", () => {
34+
for (let i = 0; i <= 200; i += 10) {
35+
cy.get("#1-extended").trigger("mousemove", {
36+
clientX: startingPointX + i,
37+
force: true,
38+
});
39+
// eslint-disable-next-line cypress/no-unnecessary-waiting
40+
// cy.wait(0);
41+
}
42+
});
43+
44+
it("Triggers mouseup", () => {
45+
cy.get("#1-extended").trigger("mouseup", {
46+
force: true,
47+
});
48+
});
49+
50+
it("Invisible elements not effected", () => {
51+
for (let i = 13; i < 100; i += 1) {
52+
cy.get(`#${i}-extended`).should("have.css", "transform", "none");
53+
}
54+
});
55+
}
56+
);

packages/dnd/src/DnDStore/DnDStoreImp.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ class DnDStoreImp extends Store<CoreInstance> implements DnDStoreInterface {
184184
};
185185
}
186186

187-
private isElementVisibleInHorizontalViewport(currentLeft: number): boolean {
187+
private isElementVisibleViewportX(currentLeft: number): boolean {
188188
return (
189189
currentLeft >= this.scrollX &&
190190
currentLeft <= this.viewportWidth + this.scrollX
191191
);
192192
}
193193

194-
private isElementVisibleInVerticalViewport(currentTop: number): boolean {
194+
private isElementVisibleViewportY(currentTop: number): boolean {
195195
return (
196196
currentTop >= this.scrollY &&
197197
currentTop <= this.viewportHeight + this.scrollY
@@ -213,12 +213,10 @@ class DnDStoreImp extends Store<CoreInstance> implements DnDStoreInterface {
213213
}
214214

215215
let isVisible =
216-
this.isElementVisibleInVerticalViewport(
216+
this.isElementVisibleViewportY(
217217
this.registry[elmID].currentTop!
218218
) &&
219-
this.isElementVisibleInHorizontalViewport(
220-
this.registry[elmID].currentLeft!
221-
);
219+
this.isElementVisibleViewportX(this.registry[elmID].currentLeft!);
222220

223221
if (
224222
!isVisible &&
@@ -360,13 +358,15 @@ class DnDStoreImp extends Store<CoreInstance> implements DnDStoreInterface {
360358

361359
this.assignSiblingsBoundaries(sK, offset!);
362360

363-
const isVisibleY = this.isElementVisibleInVerticalViewport(currentTop!);
364-
const isVisibleX = this.isElementVisibleInHorizontalViewport(currentLeft!);
361+
const isVisibleY = this.isElementVisibleViewportY(currentTop!);
362+
const isVisibleX = this.isElementVisibleViewportX(currentLeft!);
365363

366364
// same branch
367365
this.elmIndicator.currentKy = `${sK}${pK}`;
368366

369367
if (isVisibleY && isVisibleX) {
368+
this.hasVisibleElements = true;
369+
370370
if (!this.siblingsOverflow[this.registry[id].keys.sK]) {
371371
// If we don't do this, and the list is not overflowing, then the object
372372
// will be undefined.

0 commit comments

Comments
 (0)