Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { fromEvent, merge, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { ResizableDirective } from './resizable.directive';
import { Edges } from './interfaces/edges.interface';
import { getListenOptions } from './util/get-listen-options';
import { IS_TOUCH_DEVICE } from './util/is-touch-device';

/**
Expand Down Expand Up @@ -173,8 +174,10 @@ export class ResizeHandleDirective implements OnInit, OnDestroy {
}

private listenOnTheHost<T extends Event>(eventName: string) {
return fromEvent<T>(this.element.nativeElement, eventName).pipe(
takeUntil(this.destroy$),
);
return fromEvent<T>(
this.element.nativeElement,
eventName,
getListenOptions(eventName),
).pipe(takeUntil(this.destroy$));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Options for fromEvent when listening on the host.
* Touch events need passive: false so preventDefault can be called.
* @hidden
*/
export function getListenOptions(
eventName: string,
): { passive: false } | Record<string, never> {
const isTouchEvent =
eventName === 'touchstart' ||
eventName === 'touchend' ||
eventName === 'touchcancel';
return isTouchEvent ? { passive: false } : {};
}
15 changes: 15 additions & 0 deletions projects/angular-resizable-element/src/test/resizable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ResizeEvent,
ResizeHandleDirective,
} from 'angular-resizable-element';
import { getListenOptions } from '../lib/util/get-listen-options';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { expect } from 'chai';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -506,6 +507,20 @@ describe('resizable directive', () => {
});
});

describe('touch event listeners', () => {
['touchstart', 'touchend', 'touchcancel'].forEach((eventName) => {
it(`when eventName is ${eventName}, getListenOptions returns passive: false so fromEvent is called with passive: false`, () => {
expect(getListenOptions(eventName)).to.deep.equal({ passive: false });
});
});

['mousedown', 'mouseup'].forEach((eventName) => {
it(`when eventName is ${eventName}, getListenOptions returns empty options`, () => {
expect(getListenOptions(eventName)).to.deep.equal({});
});
});
});

describe('handle outside of element', () => {
let domEvents: Array<{
name: string;
Expand Down
Loading