From 56f77ad2ded823149c7bd76ce5b50f9aaefdd92e Mon Sep 17 00:00:00 2001 From: Damyan Petev Date: Tue, 17 Sep 2019 14:50:07 +0300 Subject: [PATCH] fix(grids): limit cell double tap handler to just iOS #2538 --- projects/igniteui-angular/src/lib/core/utils.ts | 9 +++++++++ .../igniteui-angular/src/lib/grids/cell.component.ts | 12 ++++++++---- .../igniteui-angular/src/lib/grids/grid/cell.spec.ts | 11 ++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/projects/igniteui-angular/src/lib/core/utils.ts b/projects/igniteui-angular/src/lib/core/utils.ts index 1481ae973af..8f97abe4aee 100644 --- a/projects/igniteui-angular/src/lib/core/utils.ts +++ b/projects/igniteui-angular/src/lib/core/utils.ts @@ -226,6 +226,15 @@ export function isFirefox(): boolean { return firefoxBrowser; } +/** + * @hidden + * TODO: make injectable, check isPlatformBrowser() + */ +export function isIOS(): boolean { + const iosBrowser = typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window); + return iosBrowser; +} + /** * @hidden */ diff --git a/projects/igniteui-angular/src/lib/grids/cell.component.ts b/projects/igniteui-angular/src/lib/grids/cell.component.ts index 829958623b3..b5292a4ace3 100644 --- a/projects/igniteui-angular/src/lib/grids/cell.component.ts +++ b/projects/igniteui-angular/src/lib/grids/cell.component.ts @@ -18,7 +18,9 @@ import { IgxSelectionAPIService } from '../core/selection'; import { IgxTextHighlightDirective } from '../directives/text-highlight/text-highlight.directive'; import { GridBaseAPIService } from './api.service'; import { IgxColumnComponent } from './column.component'; -import { getNodeSizeViaRange, ROW_COLLAPSE_KEYS, ROW_EXPAND_KEYS, SUPPORTED_KEYS, NAVIGATION_KEYS, isIE, isLeftClick } from '../core/utils'; +import { + getNodeSizeViaRange, ROW_COLLAPSE_KEYS, ROW_EXPAND_KEYS, SUPPORTED_KEYS, NAVIGATION_KEYS, isIE, isLeftClick, isIOS +} from '../core/utils'; import { State } from '../services/index'; import { IgxGridBaseComponent, IGridEditEventArgs, IGridDataBindable } from './grid-base.component'; import { IgxGridSelectionService, ISelectionNode, IgxGridCRUDService } from '../core/grid-selection'; @@ -563,9 +565,11 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy { this.nativeElement.addEventListener('focusout', this.focusOut); } }); - this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, { - cssProps: { } /* don't disable user-select, etc */ - } as HammerOptions); + if (isIOS()) { + this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, { + cssProps: { } /* don't disable user-select, etc */ + } as HammerOptions); + } } /** diff --git a/projects/igniteui-angular/src/lib/grids/grid/cell.spec.ts b/projects/igniteui-angular/src/lib/grids/grid/cell.spec.ts index 93ae3d0a30b..c9587fe6f22 100644 --- a/projects/igniteui-angular/src/lib/grids/grid/cell.spec.ts +++ b/projects/igniteui-angular/src/lib/grids/grid/cell.spec.ts @@ -9,6 +9,7 @@ import { configureTestSuite } from '../../test-utils/configure-suite'; import { IgxStringFilteringOperand, IgxNumberFilteringOperand } from '../../data-operations/filtering-condition'; import { SampleTestData } from '../../test-utils/sample-test-data.spec'; import { HammerGesturesManager } from '../../core/touch'; +import * as utils from '../../core/utils'; const DEBOUNCETIME = 30; @@ -186,8 +187,16 @@ describe('IgxGrid - Cell component', () => { expect(firstCell).toBe(fix.componentInstance.clickedCell); }); - it('Should handle doubletap, trigger onDoubleClick event', () => { + it('Should not attach doubletap handler for non-iOS', () => { const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener'); + spyOn(utils, 'isIOS').and.returnValue(false); + const fix = TestBed.createComponent(DefaultGridComponent); + fix.detectChanges(); + }); + + it('Should handle doubletap on iOS, trigger onDoubleClick event', () => { + const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener'); + spyOn(utils, 'isIOS').and.returnValue(true); const fix = TestBed.createComponent(DefaultGridComponent); fix.detectChanges();