Skip to content

Commit

Permalink
Merge pull request #14223 from IgniteUI/mkirova/fix-14116-16.1.x
Browse files Browse the repository at this point in the history
fix(IgxGrid): Add checks in case cell is no longer in view.
  • Loading branch information
kdinev committed May 16, 2024
2 parents ca2a867 + 6f6714c commit b61eaad
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions projects/igniteui-angular/src/lib/grids/common/crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit b61eaad

Please sign in to comment.