Skip to content

Commit

Permalink
fix(issue#935): Prevent WheelEvent from propagating
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Gutmann committed Jun 18, 2019
1 parent 2ce77f4 commit 1501ba5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/eventListeners/wheelEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ function wheelEventHandler(evt) {
return;
}

// Prevent triggering MouseWheel events that are not real scroll events:
// E.g. when clicking the MiddleMouseWheelButton, a deltaY of 0 is emitted.
// See https://github.com/cornerstonejs/cornerstoneTools/issues/935
if (evt.deltaY > -1 && evt.deltaY < 1) {
return;
}

evt.preventDefault();

const { pageX, pageY } = evt;
Expand Down
19 changes: 19 additions & 0 deletions src/eventListeners/wheelEventListener.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,23 @@ describe('eventListeners/wheelEventListener.js', () => {
// Fire Away!
localElement.dispatchEvent(new Event('wheel'));
});

it('does not emit an `cornerstonetoolsmousewheel` event when scrolling less than one pixel', () => {
// Setup
const localElement = document.createElement('div');
const scrollCloseToZeroPixel = 0.00001;
const middleMouseButtonClickedEvent = new WheelEvent('wheel', { deltaY: scrollCloseToZeroPixel });

// Assert
localElement.addEventListener('cornerstonetoolsmousewheel', (evt) => {
expect(false).toBe(true, 'Unwanted event fired');
});

// SUT
wheelEventListener.enable(localElement);

// Fire Away!
localElement.dispatchEvent(middleMouseButtonClickedEvent);
});

});

0 comments on commit 1501ba5

Please sign in to comment.