Skip to content

Commit e1d18b2

Browse files
committed
fix(grid): improve focusout handling to clear active node correctly
1 parent 6bd30fe commit e1d18b2

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3709,14 +3709,26 @@ 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) => {
3712+
fromEvent(this.nativeElement, 'focusout').pipe(filter(() => !!this.navigation.activeNode), destructor).subscribe((event: FocusEvent) => {
37133713
const activeNode = this.navigation.activeNode;
3714-
if (!this.crudService.cell && !!activeNode &&
3715-
((event.target === this.tbody.nativeElement && activeNode.row >= 0 &&
3716-
activeNode.row < this.dataView.length)
3717-
|| (event.target === this.theadRow.nativeElement && activeNode.row === -1)
3718-
|| (event.target === this.tfoot.nativeElement && activeNode.row === this.dataView.length)) &&
3719-
!(this.rowEditable && this.crudService.rowEditingBlocked && this.crudService.rowInEditMode)) {
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) {
37203732
this.clearActiveNode();
37213733
}
37223734
});

0 commit comments

Comments
 (0)