@@ -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 }
0 commit comments