Skip to content

Commit 656a66a

Browse files
Zneekyrkaraivanov
andauthored
fix(grid): Fix filtering UI mousedown event handling (#14467)
Co-authored-by: Radoslav Karaivanov <[email protected]>
1 parent a22f0de commit 656a66a

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

projects/igniteui-angular/src/lib/grids/grid/grid-filtering-ui.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,6 +2747,30 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
27472747
filterUIRow = fix.debugElement.query(By.css(FILTER_UI_ROW));
27482748
expect(filterUIRow).toBeNull('Default filter template was found on a column with custom filtering.');
27492749
}));
2750+
2751+
it('Should not prevent mousedown event when target is within the filter cell template', fakeAsync(() => {
2752+
const filterCell = GridFunctions.getFilterCell(fix, 'ProductName');
2753+
const input = filterCell.query(By.css('input')).nativeElement;
2754+
2755+
const mousedownEvent = new MouseEvent('mousedown', { bubbles: true });
2756+
const preventDefaultSpy = spyOn(mousedownEvent, 'preventDefault');
2757+
input.dispatchEvent(mousedownEvent, { bubbles: true });
2758+
fix.detectChanges();
2759+
2760+
expect(preventDefaultSpy).not.toHaveBeenCalled();
2761+
}));
2762+
2763+
it('Should prevent mousedown event when target is filter cell or its parent elements', fakeAsync(() => {
2764+
const filteringCells = fix.debugElement.queryAll(By.css(FILTER_UI_CELL));
2765+
const firstCell = filteringCells[0].nativeElement;
2766+
2767+
const mousedownEvent = new MouseEvent('mousedown', { bubbles: true });
2768+
const preventDefaultSpy = spyOn(mousedownEvent, 'preventDefault');
2769+
firstCell.dispatchEvent(mousedownEvent);
2770+
fix.detectChanges();
2771+
2772+
expect(preventDefaultSpy).toHaveBeenCalled();
2773+
}));
27502774
});
27512775

27522776
describe(null, () => {
@@ -2823,6 +2847,7 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
28232847

28242848
expect(grid.rowList.length).toEqual(1);
28252849
}));
2850+
28262851
});
28272852

28282853
describe('Filtering events', () => {

projects/igniteui-angular/src/lib/grids/headers/grid-header-group.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,12 @@ export class IgxGridHeaderGroupComponent implements DoCheck {
262262
*/
263263
@HostListener('mousedown', ['$event'])
264264
public onMouseDown(event: MouseEvent): void {
265-
// hack for preventing text selection in IE and Edge while dragging the resize element
266-
event.preventDefault();
265+
if (!this.grid.allowFiltering ||
266+
(event.composedPath().findIndex(el =>
267+
(el as Element).tagName?.toLowerCase() === 'igx-grid-filtering-cell') < 1)) {
268+
// Hack for preventing text selection in IE and Edge while dragging the resize element
269+
event.preventDefault();
270+
}
267271
}
268272

269273
/**

0 commit comments

Comments
 (0)