Skip to content

Commit f6f0d8b

Browse files
committed
refactor(for-of): Execute focus logic only on small scrolls
1 parent 6906285 commit f6f0d8b

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -861,23 +861,11 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
861861
if (diff) {
862862
this.onChunkPreload.emit(this.state);
863863
if (!this.isRemote) {
864-
const container = this.dc.instance._viewContainer.element.nativeElement as HTMLElement;
865-
const activeElement = document.activeElement as HTMLElement;
866-
867-
// Remove focus in case the the active element is inside the view container.
868-
// Otherwise we hit an exception while doing the 'small' scrolls swapping.
869-
// For more information:
870-
//
871-
// https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild
872-
// https://bugs.chromium.org/p/chromium/issues/detail?id=432392
873-
if (container.contains(document.activeElement)) {
874-
activeElement.blur();
875-
}
876-
/*recalculate and apply page size.*/
877-
if (diff > 0 && diff <= this.MAX_PERF_SCROLL_DIFF) {
878-
this.moveApplyScrollNext(prevStart);
879-
} else if (diff < 0 && Math.abs(diff) <= this.MAX_PERF_SCROLL_DIFF) {
880-
this.moveApplyScrollPrev(prevStart);
864+
865+
// recalculate and apply page size.
866+
if (diff && Math.abs(diff) <= this.MAX_PERF_SCROLL_DIFF) {
867+
this.scrollFocus();
868+
diff > 0 ? this.moveApplyScrollNext(prevStart) : this.moveApplyScrollPrev(prevStart);
881869
} else {
882870
this.fixedApplyScroll();
883871
}
@@ -954,6 +942,27 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
954942
}
955943
}
956944

945+
/**
946+
* @hidden
947+
* @internal
948+
*
949+
* Clears focus inside the virtualized container on small scroll swaps.
950+
*/
951+
protected scrollFocus(): void {
952+
const container = this.dc.instance._viewContainer.element.nativeElement as HTMLElement;
953+
const activeElement = document.activeElement as HTMLElement;
954+
955+
// Remove focus in case the the active element is inside the view container.
956+
// Otherwise we hit an exception while doing the 'small' scrolls swapping.
957+
// For more information:
958+
//
959+
// https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild
960+
// https://bugs.chromium.org/p/chromium/issues/detail?id=432392
961+
if (container.contains(document.activeElement)) {
962+
activeElement.blur();
963+
}
964+
}
965+
957966
/**
958967
* @hidden
959968
* Function that is called when scrolling horizontally

0 commit comments

Comments
 (0)