Skip to content

Commit 7e33e82

Browse files
committed
fix(grid): update focus handling to use focusin event for clearing active node
1 parent e1d18b2 commit 7e33e82

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

projects/igniteui-angular/grids/grid/src/cell-merge.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,11 +1161,8 @@ describe('IgxGrid - Cell merging #grid', () => {
11611161
const parentRowDE = parentRows[0];
11621162
const parentCells = parentRowDE.queryAll(By.css('.igx-grid__td'));
11631163
const parentCellDE = parentCells[1];
1164-
childCellDE.nativeElement.dispatchEvent(new FocusEvent('focusout', {
1165-
bubbles: true,
1166-
relatedTarget: parentCellDE.nativeElement
1167-
}));
11681164
UIInteractions.simulateClickAndSelectEvent(parentCellDE.nativeElement);
1165+
parentCellDE.nativeElement.dispatchEvent(new FocusEvent('focusin', { bubbles: true }));
11691166
await wait(1);
11701167
fix.detectChanges();
11711168

projects/igniteui-angular/grids/grid/src/grid-base.directive.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3709,29 +3709,21 @@ export abstract class IgxGridBaseDirective implements GridType,
37093709
*/
37103710
public _setupListeners() {
37113711
const destructor = takeUntil<any>(this.destroy$);
3712-
fromEvent(this.nativeElement, 'focusout').pipe(filter(() => !!this.navigation.activeNode), destructor).subscribe((event: FocusEvent) => {
3713-
const activeNode = this.navigation.activeNode;
3714-
if (this.crudService.cell || !activeNode) {
3715-
return;
3716-
}
3717-
const nextFocused = event.relatedTarget as Node;
3718-
const activeElement = (nextFocused || this.document.activeElement) as Node;
3719-
const focusWithin = !!activeElement && this.nativeElement.contains(activeElement);
3720-
const allowClear = !(this.rowEditable && this.crudService.rowEditingBlocked && this.crudService.rowInEditMode);
3721-
3722-
if (!focusWithin && allowClear) {
3723-
this.clearActiveNode();
3724-
return;
3725-
}
3726-
3727-
if (((event.target === this.tbody.nativeElement && activeNode.row >= 0 &&
3728-
activeNode.row < this.dataView.length)
3729-
|| (event.target === this.theadRow.nativeElement && activeNode.row === -1)
3730-
|| (event.target === this.tfoot.nativeElement && activeNode.row === this.dataView.length)) &&
3731-
allowClear) {
3732-
this.clearActiveNode();
3733-
}
3734-
});
3712+
fromEvent(this.document, 'focusin')
3713+
.pipe(filter(() => !!this.navigation.activeNode), destructor)
3714+
.subscribe((event: FocusEvent) => {
3715+
if (this.crudService.cell || !this.navigation.activeNode) {
3716+
return;
3717+
}
3718+
if (this.rowEditable && this.crudService.rowEditingBlocked && this.crudService.rowInEditMode) {
3719+
return;
3720+
}
3721+
const target = event.target as Node;
3722+
if (target && this.nativeElement.contains(target)) {
3723+
return;
3724+
}
3725+
Promise.resolve().then(() => this.clearActiveNode());
3726+
});
37353727
this.rowAddedNotifier.pipe(destructor).subscribe(args => this.refreshGridState(args));
37363728
this.rowDeletedNotifier.pipe(destructor).subscribe(args => {
37373729
this.summaryService.deleteOperation = true;

0 commit comments

Comments
 (0)