Skip to content

Commit 1713a02

Browse files
committed
fix(grid): update focus handling to use focusin event for clearing active node
1 parent d5df6a6 commit 1713a02

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,29 +3779,21 @@ export abstract class IgxGridBaseDirective implements GridType,
37793779
*/
37803780
public _setupListeners() {
37813781
const destructor = takeUntil<any>(this.destroy$);
3782-
fromEvent(this.nativeElement, 'focusout').pipe(filter(() => !!this.navigation.activeNode), destructor).subscribe((event: FocusEvent) => {
3783-
const activeNode = this.navigation.activeNode;
3784-
if (this.crudService.cell || !activeNode) {
3785-
return;
3786-
}
3787-
const nextFocused = event.relatedTarget as Node;
3788-
const activeElement = (nextFocused || this.document.activeElement) as Node;
3789-
const focusWithin = !!activeElement && this.nativeElement.contains(activeElement);
3790-
const allowClear = !(this.rowEditable && this.crudService.rowEditingBlocked && this.crudService.rowInEditMode);
3791-
3792-
if (!focusWithin && allowClear) {
3793-
this.clearActiveNode();
3794-
return;
3795-
}
3796-
3797-
if (((event.target === this.tbody.nativeElement && activeNode.row >= 0 &&
3798-
activeNode.row < this.dataView.length)
3799-
|| (event.target === this.theadRow.nativeElement && activeNode.row === -1)
3800-
|| (event.target === this.tfoot.nativeElement && activeNode.row === this.dataView.length)) &&
3801-
allowClear) {
3802-
this.clearActiveNode();
3803-
}
3804-
});
3782+
fromEvent(this.document, 'focusin')
3783+
.pipe(filter(() => !!this.navigation.activeNode), destructor)
3784+
.subscribe((event: FocusEvent) => {
3785+
if (this.crudService.cell || !this.navigation.activeNode) {
3786+
return;
3787+
}
3788+
if (this.rowEditable && this.crudService.rowEditingBlocked && this.crudService.rowInEditMode) {
3789+
return;
3790+
}
3791+
const target = event.target as Node;
3792+
if (target && this.nativeElement.contains(target)) {
3793+
return;
3794+
}
3795+
Promise.resolve().then(() => this.clearActiveNode());
3796+
});
38053797
this.rowAddedNotifier.pipe(destructor).subscribe(args => this.refreshGridState(args));
38063798
this.rowDeletedNotifier.pipe(destructor).subscribe(args => {
38073799
this.summaryService.deleteOperation = true;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,11 +1154,8 @@ describe('IgxGrid - Cell merging #grid', () => {
11541154
const parentRowDE = parentRows[0];
11551155
const parentCells = parentRowDE.queryAll(By.css('.igx-grid__td'));
11561156
const parentCellDE = parentCells[1];
1157-
childCellDE.nativeElement.dispatchEvent(new FocusEvent('focusout', {
1158-
bubbles: true,
1159-
relatedTarget: parentCellDE.nativeElement
1160-
}));
11611157
UIInteractions.simulateClickAndSelectEvent(parentCellDE.nativeElement);
1158+
parentCellDE.nativeElement.dispatchEvent(new FocusEvent('focusin', { bubbles: true }));
11621159
await wait(1);
11631160
fix.detectChanges();
11641161

0 commit comments

Comments
 (0)