Skip to content

Commit

Permalink
Merge pull request #698 from mathuo/696-touch-support-for-dragging-do…
Browse files Browse the repository at this point in the history
…ckview-panels

feat: ensure use of pointerevents for touch support
  • Loading branch information
mathuo authored Aug 28, 2024
2 parents d519c23 + 1033b80 commit fc7b9fb
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('defaultTab', () => {

let el = cut.element.querySelector('.dv-default-tab-action');

fireEvent.mouseDown(el!);
fireEvent.pointerDown(el!);
expect(api.close).toHaveBeenCalledTimes(0);

fireEvent.click(el!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ describe('tabsContainer', () => {
onDidRemovePanel: jest.fn(),
element: document.createElement('div'),
addFloatingGroup: jest.fn(),
doSetGroupActive: jest.fn(),
});

const groupPanelMock = jest.fn<DockviewGroupPanel, []>(() => {
Expand Down Expand Up @@ -486,10 +487,11 @@ describe('tabsContainer', () => {
return { top: 10, left: 20, width: 0, height: 0 } as any;
});

const event = new KeyboardEvent('mousedown', { shiftKey: true });
const event = new KeyboardEvent('pointerdown', { shiftKey: true });
const eventPreventDefaultSpy = jest.spyOn(event, 'preventDefault');
fireEvent(container, event);

expect(accessor.doSetGroupActive).toHaveBeenCalledWith(groupPanel);
expect(accessor.addFloatingGroup).toHaveBeenCalledWith(groupPanel, {
x: 100,
y: 60,
Expand All @@ -498,7 +500,7 @@ describe('tabsContainer', () => {
expect(accessor.addFloatingGroup).toHaveBeenCalledTimes(1);
expect(eventPreventDefaultSpy).toHaveBeenCalledTimes(1);

const event2 = new KeyboardEvent('mousedown', { shiftKey: false });
const event2 = new KeyboardEvent('pointerdown', { shiftKey: false });
const eventPreventDefaultSpy2 = jest.spyOn(event2, 'preventDefault');
fireEvent(container, event2);

Expand All @@ -513,6 +515,7 @@ describe('tabsContainer', () => {
onDidRemovePanel: jest.fn(),
element: document.createElement('div'),
addFloatingGroup: jest.fn(),
doSetGroupActive: jest.fn(),
});

const groupPanelMock = jest.fn<DockviewGroupPanel, []>(() => {
Expand Down Expand Up @@ -540,14 +543,15 @@ describe('tabsContainer', () => {
return { top: 10, left: 20, width: 0, height: 0 } as any;
});

const event = new KeyboardEvent('mousedown', { shiftKey: true });
const event = new KeyboardEvent('pointerdown', { shiftKey: true });
const eventPreventDefaultSpy = jest.spyOn(event, 'preventDefault');
fireEvent(container, event);

expect(accessor.doSetGroupActive).toHaveBeenCalledWith(groupPanel);
expect(accessor.addFloatingGroup).toHaveBeenCalledTimes(0);
expect(eventPreventDefaultSpy).toHaveBeenCalledTimes(0);

const event2 = new KeyboardEvent('mousedown', { shiftKey: false });
const event2 = new KeyboardEvent('pointerdown', { shiftKey: false });
const eventPreventDefaultSpy2 = jest.spyOn(event2, 'preventDefault');
fireEvent(container, event2);

Expand Down Expand Up @@ -595,7 +599,7 @@ describe('tabsContainer', () => {
const el = cut.element.querySelector('.tab')!;
expect(el).toBeTruthy();

const event = new KeyboardEvent('mousedown', { shiftKey: true });
const event = new KeyboardEvent('pointerdown', { shiftKey: true });
const preventDefaultSpy = jest.spyOn(event, 'preventDefault');
fireEvent(el, event);

Expand Down
24 changes: 12 additions & 12 deletions packages/dockview-core/src/__tests__/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ describe('events', () => {

const disposable = addDisposableWindowListener(
element as any,
'mousedown',
'pointerdown',
handler,
true
);

expect(element.addEventListener).toBeCalledTimes(1);
expect(element.addEventListener).toHaveBeenCalledWith(
'mousedown',
'pointerdown',
handler,
true
);
Expand All @@ -171,7 +171,7 @@ describe('events', () => {
expect(element.addEventListener).toBeCalledTimes(1);
expect(element.removeEventListener).toBeCalledTimes(1);
expect(element.removeEventListener).toBeCalledWith(
'mousedown',
'pointerdown',
handler,
true
);
Expand All @@ -187,13 +187,13 @@ describe('events', () => {

const disposable = addDisposableWindowListener(
element as any,
'mousedown',
'pointerdown',
handler
);

expect(element.addEventListener).toBeCalledTimes(1);
expect(element.addEventListener).toHaveBeenCalledWith(
'mousedown',
'pointerdown',
handler,
undefined
);
Expand All @@ -204,7 +204,7 @@ describe('events', () => {
expect(element.addEventListener).toBeCalledTimes(1);
expect(element.removeEventListener).toBeCalledTimes(1);
expect(element.removeEventListener).toBeCalledWith(
'mousedown',
'pointerdown',
handler,
undefined
);
Expand All @@ -220,14 +220,14 @@ describe('events', () => {

const disposable = addDisposableListener(
element as any,
'mousedown',
'pointerdown',
handler,
true
);

expect(element.addEventListener).toBeCalledTimes(1);
expect(element.addEventListener).toHaveBeenCalledWith(
'mousedown',
'pointerdown',
handler,
true
);
Expand All @@ -238,7 +238,7 @@ describe('events', () => {
expect(element.addEventListener).toBeCalledTimes(1);
expect(element.removeEventListener).toBeCalledTimes(1);
expect(element.removeEventListener).toBeCalledWith(
'mousedown',
'pointerdown',
handler,
true
);
Expand All @@ -254,13 +254,13 @@ describe('events', () => {

const disposable = addDisposableListener(
element as any,
'mousedown',
'pointerdown',
handler
);

expect(element.addEventListener).toBeCalledTimes(1);
expect(element.addEventListener).toHaveBeenCalledWith(
'mousedown',
'pointerdown',
handler,
undefined
);
Expand All @@ -271,7 +271,7 @@ describe('events', () => {
expect(element.addEventListener).toBeCalledTimes(1);
expect(element.removeEventListener).toBeCalledTimes(1);
expect(element.removeEventListener).toBeCalledWith(
'mousedown',
'pointerdown',
handler,
undefined
);
Expand Down
2 changes: 1 addition & 1 deletion packages/dockview-core/src/dnd/groupDragHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class GroupDragHandler extends DragHandler {
this.addDisposables(
addDisposableListener(
element,
'mousedown',
'pointerdown',
(e) => {
if (e.shiftKey) {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class DefaultTab extends CompositeDisposable implements ITabRenderer {
this._element.appendChild(this.action);

this.addDisposables(
addDisposableListener(this.action, 'mousedown', (ev) => {
addDisposableListener(this.action, 'pointerdown', (ev) => {
ev.preventDefault();
})
);
Expand All @@ -46,7 +46,7 @@ export class DefaultTab extends CompositeDisposable implements ITabRenderer {
this._title = event.title;
this.render();
}),
addDisposableListener(this.action, 'mousedown', (ev) => {
addDisposableListener(this.action, 'pointerdown', (ev) => {
ev.preventDefault();
}),
addDisposableListener(this.action, 'click', (ev) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/dockview-core/src/dockview/components/tab/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class Tab extends CompositeDisposable {
this._onDragStart.fire(event);
}),
dragHandler,
addDisposableListener(this._element, 'mousedown', (event) => {
addDisposableListener(this._element, 'pointerdown', (event) => {
if (event.defaultPrevented) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class TabsContainer
}),
addDisposableListener(
this.voidContainer.element,
'mousedown',
'pointerdown',
(event) => {
const isFloatingGroupsEnabled =
!this.accessor.options.disableFloatingGroups;
Expand All @@ -278,7 +278,7 @@ export class TabsContainer
}
}
),
addDisposableListener(this.tabContainer, 'mousedown', (event) => {
addDisposableListener(this.tabContainer, 'pointerdown', (event) => {
if (event.defaultPrevented) {
return;
}
Expand Down
16 changes: 9 additions & 7 deletions packages/dockview-core/src/overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class AriaLevelTracker {
private update(): void {
for (let i = 0; i < this._orderedList.length; i++) {
this._orderedList[i].setAttribute('aria-level', `${i}`);
this._orderedList[i].style.zIndex = `${DEFAULT_OVERLAY_Z_INDEX + i * 2}`;
this._orderedList[i].style.zIndex = `${
DEFAULT_OVERLAY_Z_INDEX + i * 2
}`;
}
}
}
Expand Down Expand Up @@ -241,7 +243,7 @@ export class Overlay extends CompositeDisposable {
iframes.release();
},
},
addDisposableWindowListener(window, 'mousemove', (e) => {
addDisposableWindowListener(window, 'pointermove', (e) => {
const containerRect =
this.options.container.getBoundingClientRect();
const x = e.clientX - containerRect.left;
Expand Down Expand Up @@ -342,7 +344,7 @@ export class Overlay extends CompositeDisposable {

this.addDisposables(
move,
addDisposableListener(dragTarget, 'mousedown', (event) => {
addDisposableListener(dragTarget, 'pointerdown', (event) => {
if (event.defaultPrevented) {
event.preventDefault();
return;
Expand All @@ -358,7 +360,7 @@ export class Overlay extends CompositeDisposable {
}),
addDisposableListener(
this.options.content,
'mousedown',
'pointerdown',
(event) => {
if (event.defaultPrevented) {
return;
Expand All @@ -377,7 +379,7 @@ export class Overlay extends CompositeDisposable {
),
addDisposableListener(
this.options.content,
'mousedown',
'pointerdown',
() => {
arialLevelTracker.push(this._element);
},
Expand Down Expand Up @@ -409,7 +411,7 @@ export class Overlay extends CompositeDisposable {

this.addDisposables(
move,
addDisposableListener(resizeHandleElement, 'mousedown', (e) => {
addDisposableListener(resizeHandleElement, 'pointerdown', (e) => {
e.preventDefault();

let startPosition: {
Expand All @@ -422,7 +424,7 @@ export class Overlay extends CompositeDisposable {
const iframes = disableIframePointEvents();

move.value = new CompositeDisposable(
addDisposableWindowListener(window, 'mousemove', (e) => {
addDisposableWindowListener(window, 'pointermove', (e) => {
const containerRect =
this.options.container.getBoundingClientRect();
const overlayRect =
Expand Down
4 changes: 2 additions & 2 deletions packages/dockview/src/__tests__/dockview/defaultTab.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('defaultTab', () => {
expect(element.querySelector('.dv-default-tab-action')).toBeTruthy();
});

test('that mouseDown on close button prevents panel becoming active', async () => {
test('that pointerDown on close button prevents panel becoming active', async () => {
const api = fromPartial<DockviewPanelApi>({
setActive: jest.fn(),
onDidTitleChange: jest.fn().mockImplementation(() => Disposable.NONE),
Expand All @@ -197,7 +197,7 @@ describe('defaultTab', () => {
'.dv-default-tab-action'
) as HTMLElement;

fireEvent.mouseDown(btn);
fireEvent.pointerDown(btn);
expect(api.setActive).toHaveBeenCalledTimes(0);

fireEvent.click(element);
Expand Down
4 changes: 2 additions & 2 deletions packages/dockview/src/dockview/defaultTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const DockviewDefaultTab: React.FunctionComponent<
[api, closeActionOverride]
);

const onMouseDown = React.useCallback((e: React.MouseEvent) => {
const onPointerDown = React.useCallback((e: React.MouseEvent) => {
e.preventDefault();
}, []);

Expand Down Expand Up @@ -79,7 +79,7 @@ export const DockviewDefaultTab: React.FunctionComponent<
{!hideClose && (
<div
className="dv-default-tab-action"
onMouseDown={onMouseDown}
onPointerDown={onPointerDown}
onClick={onClose}
>
<CloseButton />
Expand Down

0 comments on commit fc7b9fb

Please sign in to comment.