Skip to content

Commit 255ce3c

Browse files
committed
refactor(*): Address review comments
Also while focusing the grid body, call with preventFocus because Chromium based browsers try to center by scrolling into view the focused node
1 parent c654203 commit 255ce3c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,6 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
864864

865865
// recalculate and apply page size.
866866
if (diff && Math.abs(diff) <= this.MAX_PERF_SCROLL_DIFF) {
867-
this.scrollFocus();
868867
diff > 0 ? this.moveApplyScrollNext(prevStart) : this.moveApplyScrollPrev(prevStart);
869868
} else {
870869
this.fixedApplyScroll();
@@ -886,6 +885,8 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
886885

887886
for (let i = start; i < end && this.igxForOf[i] !== undefined; i++) {
888887
const embView = this._embeddedViews.shift();
888+
this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE)
889+
|| embView.rootNodes[0].nextElementSibling);
889890
const view = container.detach(0);
890891

891892
this.updateTemplateContext(embView.context, i);
@@ -902,6 +903,8 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
902903
const container = this.dc.instance._vcr as ViewContainerRef;
903904
for (let i = prevIndex - 1; i >= this.state.startIndex && this.igxForOf[i] !== undefined; i--) {
904905
const embView = this._embeddedViews.pop();
906+
this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE)
907+
|| embView.rootNodes[0].nextElementSibling);
905908
const view = container.detach(container.length - 1);
906909

907910
this.updateTemplateContext(embView.context, i);
@@ -948,8 +951,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
948951
*
949952
* Clears focus inside the virtualized container on small scroll swaps.
950953
*/
951-
protected scrollFocus(): void {
952-
const container = this.dc.instance._viewContainer.element.nativeElement as HTMLElement;
954+
protected scrollFocus(node?: HTMLElement): void {
953955
const activeElement = document.activeElement as HTMLElement;
954956

955957
// Remove focus in case the the active element is inside the view container.
@@ -958,7 +960,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
958960
//
959961
// https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild
960962
// https://bugs.chromium.org/p/chromium/issues/detail?id=432392
961-
if (container.contains(document.activeElement)) {
963+
if (node && node.contains(document.activeElement)) {
962964
activeElement.blur();
963965
}
964966
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
666666
}
667667
}
668668
crud.end();
669-
this.grid.tbody.nativeElement.focus();
669+
this.grid.tbody.nativeElement.focus({ preventScroll: true });
670670
this.grid.notifyChanges();
671671
crud.begin(this);
672672
return;

0 commit comments

Comments
 (0)