Skip to content

Commit

Permalink
fix(grid): Fix filtering UI mousedown event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Zneeky committed Jul 3, 2024
1 parent a1a2407 commit f7ce350
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,30 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
filterUIRow = fix.debugElement.query(By.css(FILTER_UI_ROW));
expect(filterUIRow).toBeNull('Default filter template was found on a column with custom filtering.');
}));

it('Should not prevent mousedown event when target is within the filter cell template', fakeAsync(() => {
const filterCell = GridFunctions.getFilterCell(fix, 'ProductName');
const input = filterCell.query(By.css('input')).nativeElement;

const mousedownEvent = new MouseEvent('mousedown', { bubbles: true });
const preventDefaultSpy = spyOn(mousedownEvent, 'preventDefault');
input.dispatchEvent(mousedownEvent, { bubbles: true });
fix.detectChanges();

expect(preventDefaultSpy).not.toHaveBeenCalled();
}));

it('Should prevent mousedown event when target is filter cell or its parent elements', fakeAsync(() => {
const filteringCells = fix.debugElement.queryAll(By.css(FILTER_UI_CELL));
const firstCell = filteringCells[0].nativeElement;

const mousedownEvent = new MouseEvent('mousedown', { bubbles: true });
const preventDefaultSpy = spyOn(mousedownEvent, 'preventDefault');
firstCell.dispatchEvent(mousedownEvent);
fix.detectChanges();

expect(preventDefaultSpy).toHaveBeenCalled();
}));
});

describe(null, () => {
Expand Down Expand Up @@ -2827,6 +2851,7 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {

expect(grid.rowList.length).toEqual(1);
}));

});

describe('Filtering events', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,12 @@ export class IgxGridHeaderGroupComponent implements DoCheck {
*/
@HostListener('mousedown', ['$event'])
public onMouseDown(event: MouseEvent): void {
// hack for preventing text selection in IE and Edge while dragging the resize element
event.preventDefault();
if (!this.grid.allowFiltering ||
(event.composedPath().findIndex(el =>
(el as Element).tagName?.toLowerCase() === 'igx-grid-filtering-cell') < 1)) {
// Hack for preventing text selection in IE and Edge while dragging the resize element
event.preventDefault();
}
}

/**
Expand Down

0 comments on commit f7ce350

Please sign in to comment.