Skip to content

Commit b61eaad

Browse files
authored
Merge pull request #14223 from IgniteUI/mkirova/fix-14116-16.1.x
fix(IgxGrid): Add checks in case cell is no longer in view.
2 parents ca2a867 + 6f6714c commit b61eaad

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

projects/igniteui-angular/src/lib/grids/common/crud.service.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,13 @@ export class IgxCellCrudState {
229229
// this is needed when we are not using ngModel to update the editValue
230230
// so that the change event of the inlineEditorTemplate is hit before
231231
// trying to update any cell
232-
const cellNode = this.grid.gridAPI.get_cell_by_index(this.cell.id.rowIndex, this.cell.column.field).nativeElement;
233-
const document = cellNode.getRootNode() as Document | ShadowRoot;
234-
const activeElement = document.activeElement as HTMLElement;
235-
activeElement.blur();
232+
const cellNode = this.grid.gridAPI.get_cell_by_index(this.cell.id.rowIndex, this.cell.column.field)?.nativeElement;
233+
let activeElement;
234+
if (cellNode) {
235+
const document = cellNode.getRootNode() as Document | ShadowRoot;
236+
activeElement = document.activeElement as HTMLElement;
237+
activeElement.blur();
238+
}
236239

237240
const formControl = this.grid.validation.getFormControl(this.cell.id.rowID, this.cell.column.field);
238241
if (this.grid.validationTrigger === 'blur' && this.cell.pendingValue !== undefined) {
@@ -260,7 +263,7 @@ export class IgxCellCrudState {
260263
const args = this.cellEdit(event);
261264
if (args.cancel) {
262265
// the focus is needed when we cancel the cellEdit so that the activeElement stays on the editor template
263-
activeElement.focus();
266+
activeElement?.focus();
264267
return args;
265268
}
266269

0 commit comments

Comments
 (0)