Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ie 11 window scroll fix #1091

Merged
merged 4 commits into from
Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/view/drag-handle/sensor/create-keyboard-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,16 @@ export default ({
// https://twitter.com/alexandereardon/status/985994224867819520
// Using capture: false here as we want to avoid intercepting droppable scroll requests
options: { capture: false },
fn: callbacks.onWindowScroll,
fn: (event: UIEvent) => {
// IE11 fix:
// Scrollable events still bubble up and are caught by this handler in ie11.
// We can ignore this event
if (event.currentTarget !== getWindow()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexreardon This actually doesn't fix the issue for IE11.

return;
}

callbacks.onWindowScroll();
},
},
// Cancel on page visibility change
{
Expand Down
9 changes: 8 additions & 1 deletion src/view/drag-handle/sensor/create-mouse-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,14 @@ export default ({
// Using capture: false here as we want to avoid intercepting droppable scroll requests
// TODO: can result in awkward drop position
options: { passive: true, capture: false },
fn: () => {
fn: (event: UIEvent) => {
// IE11 fix:
// Scrollable events still bubble up and are caught by this handler in ie11.
// We can ignore this event
if (event.currentTarget !== getWindow()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexreardon This actually doesn't fix the issue for IE11.

return;
}

// stop a pending drag
if (state.pending) {
stopPendingDrag();
Expand Down
18 changes: 18 additions & 0 deletions test/unit/view/drag-handle/keyboard-sensor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ describe('progress', () => {
expect(event.defaultPrevented).toBe(false);
});

it('should not fire an onWindowScroll if it is not the window scrolling (ie11 bug)', () => {
// start the lift
pressSpacebar(wrapper);

// trigger scroll event
const scrollable: HTMLElement = document.createElement('div');
const fakeEvent: Event = new Event('scroll');
Object.defineProperties(fakeEvent, {
currentTarget: {
writable: true,
value: scrollable,
},
});
window.dispatchEvent(fakeEvent);

expect(callbacks.onWindowScroll).not.toHaveBeenCalled();
});

it('should prevent using keyboard keys that modify scroll', () => {
const keys: number[] = [
keyCodes.pageUp,
Expand Down
33 changes: 32 additions & 1 deletion test/unit/view/drag-handle/mouse-sensor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,23 @@ describe('window scroll during drag', () => {
x: 100,
y: 200,
});
// no animation frame to release diff

// no animation frame to release diff
expect(
callbacksCalled(callbacks)({
onLift: 1,
onWindowScroll: 0,
}),
).toBe(true);

// releasing a frame
requestAnimationFrame.step();
expect(
callbacksCalled(callbacks)({
onLift: 1,
onWindowScroll: 1,
}),
).toBe(true);
});

it('should only trigger onWindowScroll if still dragging when the animation frame fires', () => {
Expand Down Expand Up @@ -594,6 +603,28 @@ describe('window scroll during drag', () => {
}),
).toBe(true);
});

it('should not fire an onWindowScroll if it is not the window scrolling (ie11 bug)', () => {
// start the lift
mouseDown(wrapper);
windowMouseMove({ x: 0, y: sloppyClickThreshold });
expect(callbacks.onLift).toHaveBeenCalled();

// trigger scroll event
const scrollable: HTMLElement = document.createElement('div');
const fakeEvent: Event = new Event('scroll');
Object.defineProperties(fakeEvent, {
currentTarget: {
writable: true,
value: scrollable,
},
});
window.dispatchEvent(fakeEvent);
// ensuring any events would be published
requestAnimationFrame.flush();

expect(callbacks.onWindowScroll).not.toHaveBeenCalled();
});
});

describe('finish', () => {
Expand Down
4 changes: 3 additions & 1 deletion test/unit/view/drag-handle/util/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const callbacksCalled = (callbacks: Callbacks) => ({
onMoveLeft = 0,
onDrop = 0,
onCancel = 0,
onWindowScroll = 0,
}: CallBacksCalledFn = {}) =>
callbacks.onLift.mock.calls.length === onLift &&
callbacks.onMove.mock.calls.length === onMove &&
Expand All @@ -48,7 +49,8 @@ export const callbacksCalled = (callbacks: Callbacks) => ({
callbacks.onDrop.mock.calls.length === onDrop &&
callbacks.onCancel.mock.calls.length === onCancel &&
callbacks.onMoveRight.mock.calls.length === onMoveRight &&
callbacks.onMoveLeft.mock.calls.length === onMoveLeft;
callbacks.onMoveLeft.mock.calls.length === onMoveLeft &&
callbacks.onWindowScroll.mock.calls.length === onWindowScroll;

export const whereAnyCallbacksCalled = (callbacks: Callbacks) =>
!callbacksCalled(callbacks)();
Expand Down