@@ -133,22 +133,17 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
133133 public navigateTop ( visibleColumnIndex ) {
134134 if ( this . grid . parent !== null ) {
135135 // navigating in child
136- const verticalScroll = this . grid . verticalScrollContainer . getVerticalScroll ( ) ;
137- const cellSelector = this . getCellSelector ( visibleColumnIndex ) ;
138-
139- if ( verticalScroll . scrollTop === 0 ) {
140- this . _focusScrollCellInView ( visibleColumnIndex ) ;
136+ const childContainer = this . grid . nativeElement . parentNode . parentNode ;
137+ const diff =
138+ childContainer . getBoundingClientRect ( ) . top - this . grid . rootGrid . tbody . nativeElement . getBoundingClientRect ( ) . top ;
139+ const topIsVisible = diff >= 0 ;
140+ const scrollable = this . getNextScrollable ( this . grid ) ;
141+ if ( ! topIsVisible ) {
142+ this . scrollGrid ( scrollable . grid , diff ,
143+ ( ) => super . navigateTop ( visibleColumnIndex ) ) ;
141144 } else {
142- this . scrollGrid ( this . grid , 'top' ,
143- ( ) => {
144- const cells = this . grid . nativeElement . querySelectorAll (
145- `${ cellSelector } [data-visibleIndex="${ visibleColumnIndex } "]` ) ;
146- if ( cells . length > 0 ) {
147- this . _focusScrollCellInView ( visibleColumnIndex ) ;
148- }
149- } ) ;
145+ super . navigateTop ( visibleColumnIndex ) ;
150146 }
151-
152147 } else {
153148 super . navigateTop ( visibleColumnIndex ) ;
154149 }
@@ -465,27 +460,6 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
465460 }
466461 }
467462
468- private _focusScrollCellInView ( visibleColumnIndex ) {
469- const cellSelector = this . getCellSelector ( visibleColumnIndex ) ;
470- const cells = this . grid . nativeElement . querySelectorAll (
471- `${ cellSelector } [data-visibleIndex="${ visibleColumnIndex } "]` ) ;
472- const cell = cells [ 0 ] ;
473- const childContainer = this . grid . nativeElement . parentNode . parentNode ;
474- const scrTop = this . grid . parent . verticalScrollContainer . getVerticalScroll ( ) . scrollTop ;
475- const maxScroll = this . grid . parent . verticalScrollContainer . getVerticalScroll ( ) . scrollHeight - this . grid . parent . calcHeight ;
476- const dc = childContainer . parentNode . parentNode ;
477- const scrWith = parseInt ( dc . style . top , 10 ) ;
478- const parentRowOffset = childContainer . parentNode . offsetTop + this . grid . nativeElement . offsetTop +
479- scrWith ;
480- if ( ( scrTop === 0 && parentRowOffset < 0 ) || parentRowOffset === 0 || ( scrTop === maxScroll && parentRowOffset > 0 ) ) {
481- // cell is in view
482- cell . focus ( { preventScroll : true } ) ;
483- } else {
484- // scroll parent so that cell is in view
485- this . scrollGrid ( this . grid . parent , parentRowOffset , ( ) => cell . focus ( { preventScroll : true } ) ) ;
486- }
487- }
488-
489463 private focusNextChild ( elem , visibleColumnIndex , grid ) {
490464 const gridElem = elem . querySelector ( 'igx-hierarchical-grid' ) ;
491465 const childGridID = gridElem . getAttribute ( 'id' ) ;
0 commit comments