Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(IgxGrid): Add checks in case cell is no longer in view. #14158

Merged
merged 3 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -254,10 +254,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 @@ -285,7 +288,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