Skip to content

Commit 1c52fcb

Browse files
Media editor modal: disable scroll wheel zoom while a pan/drag is active (WordPress#77863)
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
1 parent 85be0f3 commit 1c52fcb

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

packages/media-editor/src/image-editor/core/interaction-controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ export class InteractionController {
361361
handleWheel( e: WheelEvent ): void {
362362
e.preventDefault();
363363

364+
if ( this.drag ) {
365+
return;
366+
}
367+
364368
// Debounced gesture boundaries for wheel zoom.
365369
// Start on first wheel event, end after 300ms of no events.
366370
if ( ! this.wheelGestureActive ) {

packages/media-editor/src/image-editor/core/test/interaction-controller.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,31 @@ describe( 'InteractionController', () => {
465465
expect( setZoomCall![ 0 ] ).toBe( 4 );
466466
} );
467467

468+
it( 'does not zoom while pointer pan is active', () => {
469+
const state = makeState( { zoom: 2 } );
470+
const { controller } = createController( state );
471+
const el = createMockElement();
472+
473+
controller.handlePointerDown(
474+
createPointerEvent( { clientX: 100, clientY: 100 } ),
475+
el
476+
);
477+
478+
jest.clearAllMocks();
479+
480+
const wheelEvent = createWheelEvent( {
481+
deltaY: -100,
482+
currentTarget: null,
483+
} );
484+
controller.handleWheel( wheelEvent );
485+
486+
expect( wheelEvent.preventDefault ).toHaveBeenCalled();
487+
expect( actionMocks.setZoom ).not.toHaveBeenCalled();
488+
expect( actionMocks.setZoomAtPoint ).not.toHaveBeenCalled();
489+
490+
el._fire( 'pointerup', createPointerEvent() );
491+
} );
492+
468493
it( 'calls onGestureStart on first wheel, onGestureEnd after debounce', () => {
469494
jest.useFakeTimers( {
470495
doNotFake: [ 'requestAnimationFrame', 'cancelAnimationFrame' ],

0 commit comments

Comments
 (0)