Skip to content

Commit c7e03ba

Browse files
authored
Merge pull request #6204 from IgniteUI/mkirova/fix-6191
chore(*): Re-apply focus after expansion state is changed.
2 parents 0182cce + c21091e commit c7e03ba

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

projects/igniteui-angular/src/lib/directives/template-outlet/template_outlet.directive.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ export class IgxTemplateOutletDirective implements OnChanges {
6363
}
6464

6565
private _recreateView() {
66+
const prevIndex = this._viewRef ? this._viewContainerRef.indexOf(this._viewRef) : -1;
6667
// detach old and create new
67-
if (this._viewRef) {
68-
this._viewContainerRef.detach(this._viewContainerRef.indexOf(this._viewRef));
68+
if (prevIndex !== -1) {
69+
this._viewContainerRef.detach(prevIndex);
6970
}
7071
if (this.igxTemplateOutlet) {
7172
this._viewRef = this._viewContainerRef.createEmbeddedView(

projects/igniteui-angular/src/lib/grids/cell.component.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -862,15 +862,6 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
862862
}
863863
this.grid.expansionStates = expandedStates;
864864
this.grid.notifyChanges();
865-
const isVirtualized = !this.grid.verticalScrollContainer.dc.instance.notVirtual;
866-
// persist focused cell
867-
const el = this.grid.selectionService.activeElement;
868-
if (isVirtualized && el) {
869-
const cell = this.grid.gridAPI.get_cell_by_visible_index(el.row, el.column);
870-
if (cell) {
871-
cell.nativeElement.focus();
872-
}
873-
}
874865
}
875866
}
876867

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6044,4 +6044,16 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
60446044
advancedFilteringDialog.closeDialog();
60456045
}
60466046
}
6047+
6048+
protected _focusActiveCell() {
6049+
// persist focused cell
6050+
const isVirtualized = !this.verticalScrollContainer.dc.instance.notVirtual;
6051+
const el = this.selectionService.activeElement;
6052+
if (isVirtualized && el) {
6053+
const cell = this.gridAPI.get_cell_by_visible_index(el.row, el.column);
6054+
if (cell) {
6055+
cell.nativeElement.focus();
6056+
}
6057+
}
6058+
}
60476059
}

projects/igniteui-angular/src/lib/grids/grid/grid.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
598598
this.expansionStatesChange.emit(this._expansionStates);
599599
if (this.gridAPI.grid) {
600600
this.cdr.detectChanges();
601+
this._focusActiveCell();
601602
}
602603
}
603604

0 commit comments

Comments
 (0)