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 cf2e0b24db5..4ba5f090ccc 100644 --- a/projects/igniteui-angular/src/lib/grids/common/crud.service.ts +++ b/projects/igniteui-angular/src/lib/grids/common/crud.service.ts @@ -229,10 +229,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) { @@ -260,7 +263,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; }