-
Notifications
You must be signed in to change notification settings - Fork 671
T1328053 - Draggable - The drag action starts after closing Ctrl + click context menu in Safari/Chrome on MacOS #34253
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
Open
Raushen
wants to merge
6
commits into
DevExpress:main
Choose a base branch
from
Raushen:T1328053-26_2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+171
−61
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0b76ba
T1328053
Raushen ecb631f
Refactoring
Raushen f1cb89c
Refactoring
Raushen 8f08900
Fix tests
Raushen e634953
Merge branch 'main' of https://github.com/DevExpress/DevExtreme into …
Raushen 0c87b58
Merge branch 'main' of https://github.com/DevExpress/DevExtreme into …
Raushen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/devextreme/js/__internal/__tests__/draggable_mac_ctrl_click.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { | ||
| afterEach, | ||
| beforeEach, | ||
| describe, | ||
| expect, | ||
| it, | ||
| jest, | ||
| } from '@jest/globals'; | ||
| import devices from '@ts/core/m_devices'; | ||
|
|
||
| import { createDraggable, disposeDraggable, fire } from './utils'; | ||
|
|
||
| jest.mock('@ts/core/m_devices', () => { | ||
| const originalModule: any = jest.requireActual('@ts/core/m_devices'); | ||
| const device = { mac: false, deviceType: 'desktop', platform: 'generic' }; | ||
|
|
||
| return { | ||
| __esModule: true, | ||
| default: { | ||
| ...originalModule.default, | ||
| isSimulator: originalModule.default.isSimulator, | ||
| real: jest.fn().mockReturnValue(device), | ||
| current: jest.fn().mockReturnValue(device), | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| const setMac = (mac: boolean): void => { | ||
| (devices.real as jest.Mock).mockReturnValue({ mac, deviceType: 'desktop', platform: 'generic' }); | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| document.body.innerHTML = ''; | ||
| setMac(false); | ||
| }); | ||
|
|
||
| afterEach(disposeDraggable); | ||
|
|
||
| describe('Draggable macOS Ctrl+click (T1328053)', () => { | ||
| it('should not start a drag when a mouse move follows a macOS Ctrl+click', () => { | ||
| setMac(true); | ||
| const onDragStart = jest.fn(); | ||
| const draggable = createDraggable({ onDragStart }); | ||
| const element = draggable.$element().get(0); | ||
|
|
||
| fire(element, 'dxpointerdown', { ctrlKey: true, pointerType: 'mouse' }); | ||
| fire(element, 'dxpointermove', { y: 40, pointerType: 'mouse' }); | ||
|
|
||
| expect(onDragStart).not.toHaveBeenCalled(); | ||
| expect(draggable.getDragInProgress()).toBe(false); | ||
| }); | ||
|
|
||
| it('should still start a drag for a regular (non-Ctrl) click on macOS', () => { | ||
| setMac(true); | ||
| const onDragStart = jest.fn(); | ||
| const draggable = createDraggable({ onDragStart }); | ||
| const element = draggable.$element().get(0); | ||
|
|
||
| fire(element, 'dxpointerdown', { pointerType: 'mouse' }); | ||
| fire(element, 'dxpointermove', { y: 40, pointerType: 'mouse' }); | ||
|
|
||
| expect(onDragStart).toHaveBeenCalledTimes(1); | ||
| expect(draggable.getDragInProgress()).toBe(true); | ||
| }); | ||
|
|
||
| it('should still start a drag for a Ctrl+click on non-macOS platforms', () => { | ||
| setMac(false); | ||
| const onDragStart = jest.fn(); | ||
| const draggable = createDraggable({ onDragStart }); | ||
| const element = draggable.$element().get(0); | ||
|
|
||
| fire(element, 'dxpointerdown', { ctrlKey: true, pointerType: 'mouse' }); | ||
| fire(element, 'dxpointermove', { y: 40, pointerType: 'mouse' }); | ||
|
|
||
| expect(onDragStart).toHaveBeenCalledTimes(1); | ||
| expect(draggable.getDragInProgress()).toBe(true); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import eventsEngine from '@js/common/core/events/core/events_engine'; | ||
| import $ from '@js/core/renderer'; | ||
| import Draggable from '@js/ui/draggable'; | ||
|
|
||
| export const DRAGGABLE_ELEMENT_ID = 'draggable'; | ||
|
|
||
| export interface DraggableTest extends Draggable { | ||
| getDragInProgress: () => boolean; | ||
| } | ||
|
|
||
| export interface FiredEvent { | ||
| _cancelPreventDefault?: boolean; | ||
| isDefaultPrevented: () => boolean; | ||
| } | ||
|
|
||
| interface FireOptions { | ||
| x?: number; | ||
| y?: number; | ||
| ctrlKey?: boolean; | ||
| pointerType?: 'mouse' | 'touch'; | ||
| } | ||
|
|
||
| export const fire = ( | ||
| element: Element, | ||
| type: string, | ||
| { | ||
| x = 0, y = 0, ctrlKey = false, pointerType = 'touch', | ||
| }: FireOptions = {}, | ||
| ): FiredEvent => { | ||
| // @ts-expect-error -- Event is absent from the public eventsEngine type | ||
| const event: FiredEvent = eventsEngine.Event({ | ||
| type, | ||
| pageX: x, | ||
| pageY: y, | ||
| clientX: x, | ||
| clientY: y, | ||
| offset: { x, y }, | ||
| pointerType, | ||
| pointers: type === 'dxpointerup' ? [] : [{ pointerId: 1 }], | ||
| pointerId: 1, | ||
| which: 1, | ||
| ctrlKey, | ||
| }); | ||
|
|
||
| // @ts-expect-error -- trigger is absent from the public eventsEngine type | ||
| eventsEngine.trigger(element, event); | ||
|
|
||
| return event; | ||
| }; | ||
|
|
||
| export const createDraggable = (options: Record<string, unknown> = {}): DraggableTest => { | ||
| const $element = $('<div>') | ||
| .attr('id', DRAGGABLE_ELEMENT_ID) | ||
| .css({ width: '100px', height: '40px' }) | ||
| .appendTo(document.body); | ||
|
|
||
| return new Draggable($element.get(0), { autoScroll: false, ...options }) as DraggableTest; | ||
| }; | ||
|
|
||
| export const disposeDraggable = (): void => { | ||
| const instance = Draggable.getInstance($(`#${DRAGGABLE_ELEMENT_ID}`).get(0)); | ||
|
|
||
| instance?.dispose(); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,14 @@ const LEGACY_KEY_CODES = { | |
| 18: 'alt', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file contains only refactoring, without fix. |
||
| }; | ||
|
|
||
| const MOUSE_BUTTON_MAP = { | ||
| left: 1, | ||
| middle: 2, | ||
| right: 3, | ||
| back: 4, | ||
| forward: 5, | ||
| }; | ||
|
|
||
| const EVENT_SOURCES_REGEX = { | ||
| dx: /^dx/i, | ||
| mouse: /(mouse|wheel)/i, | ||
|
|
@@ -141,7 +149,6 @@ export const hasTouches = (e) => { | |
| let skipEvents = false; | ||
| export const forceSkipEvents = () => { skipEvents = true; }; | ||
| export const stopEventsSkipping = () => { skipEvents = false; }; | ||
| // eslint-disable-next-line consistent-return | ||
| export const needSkipEvent = (e) => { | ||
| // TODO: for tests | ||
| if (skipEvents) { | ||
|
|
@@ -151,7 +158,7 @@ export const needSkipEvent = (e) => { | |
| // TODO: this checking used in swipeable first move handler. is it correct? | ||
| const { target } = e; | ||
| const $target = $(target); | ||
| const isContentEditable = target?.isContentEditable || target?.hasAttribute('contenteditable'); | ||
| const isContentEditable: boolean = target?.isContentEditable || target?.hasAttribute('contenteditable'); | ||
| const touchInEditable = $target.is('input, textarea, select') || isContentEditable; | ||
|
|
||
| if (isDxMouseWheelEvent(e)) { | ||
|
|
@@ -167,12 +174,16 @@ export const needSkipEvent = (e) => { | |
| } | ||
|
|
||
| if (isMouseEvent(e)) { | ||
| return touchInEditable || e.which > 1; // only left mouse button | ||
| const isNotLeftMouseButton = e.which > MOUSE_BUTTON_MAP.left; | ||
|
|
||
| return touchInEditable || isNotLeftMouseButton; | ||
| } | ||
|
|
||
| if (isTouchEvent(e)) { | ||
| return touchInEditable && focused($target); | ||
| } | ||
|
|
||
| return false; | ||
| }; | ||
|
|
||
| export const setEventFixMethod = (func) => { fixMethod = func; }; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.