From 1c728947cb11dd683b622bd736d6973b76cfb5e3 Mon Sep 17 00:00:00 2001 From: MKirova Date: Wed, 24 Apr 2024 12:02:04 +0300 Subject: [PATCH] fix(IgxGrid): Add checks in case cell is no longer in view. --- .../src/lib/grids/common/crud.service.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/common/crud.service.ts b/projects/igniteui-angular/src/lib/grids/common/crud.service.ts index c29af6a46a6..b3316ce6a63 100644 --- a/projects/igniteui-angular/src/lib/grids/common/crud.service.ts +++ b/projects/igniteui-angular/src/lib/grids/common/crud.service.ts @@ -253,10 +253,13 @@ export class IgxCellCrudState { // this is needed when we are not using ngModel to update the editValue // so that the change event of the inlineEditorTemplate is hit before // trying to update any cell - const cellNode = this.grid.gridAPI.get_cell_by_index(this.cell.id.rowIndex, this.cell.column.field).nativeElement; - const document = cellNode.getRootNode() as Document | ShadowRoot; - const activeElement = document.activeElement as HTMLElement; - activeElement.blur(); + const cellNode = this.grid.gridAPI.get_cell_by_index(this.cell.id.rowIndex, this.cell.column.field)?.nativeElement; + let activeElement; + if (cellNode) { + const document = cellNode.getRootNode() as Document | ShadowRoot; + activeElement = document.activeElement as HTMLElement; + activeElement.blur(); + } const formControl = this.grid.validation.getFormControl(this.cell.id.rowID, this.cell.column.field); if (this.grid.validationTrigger === 'blur' && this.cell.pendingValue !== undefined) { @@ -284,7 +287,7 @@ export class IgxCellCrudState { const args = this.cellEdit(event); if (args.cancel) { // the focus is needed when we cancel the cellEdit so that the activeElement stays on the editor template - activeElement.focus(); + activeElement?.focus(); return args; }