@@ -273,7 +273,7 @@ export class IgxGridNavigationService {
273273 const cells = this . grid . nativeElement . querySelectorAll (
274274 `${ cellSelector } [data-visibleIndex="${ visibleColumnIndex } "]` ) ;
275275 if ( cells . length > 0 ) {
276- ( cells [ cells . length - 1 ] as HTMLElement ) . focus ( ) ;
276+ ( cells [ cells . length - 1 ] as HTMLElement ) . focus ( { preventScroll : true } ) ;
277277 }
278278 } ) ;
279279 }
@@ -294,13 +294,7 @@ export class IgxGridNavigationService {
294294 . pipe ( first ( ) )
295295 . subscribe ( ( ) => {
296296 const tag = rowElement . tagName . toLowerCase ( ) ;
297- const rowSelector = this . getRowSelector ( ) ;
298- if ( tag === rowSelector || tag === 'igx-grid-summary-row' ) {
299- rowElement = this . getRowByIndex ( currentRowIndex , tag ) ;
300- } else {
301- rowElement = this . grid . nativeElement . querySelector (
302- `igx-grid-groupby-row[data-rowindex="${ currentRowIndex } "]` ) ;
303- }
297+ rowElement = this . getRowByIndex ( currentRowIndex , tag ) ;
304298 this . focusPreviousElement ( rowElement , visibleColumnIndex ) ;
305299 } ) ;
306300 } else {
@@ -341,7 +335,7 @@ export class IgxGridNavigationService {
341335 }
342336
343337 protected focusElem ( rowElement , visibleColumnIndex ) {
344- if ( rowElement . tagName . toLowerCase ( ) === 'igx-grid-groupby-row' ) {
338+ if ( rowElement . tagName . toLowerCase ( ) === 'igx-grid-groupby-row' || rowElement . className === 'igx-grid__tr-container' ) {
345339 rowElement . focus ( ) ;
346340 } else {
347341 const isSummaryRow = rowElement . tagName . toLowerCase ( ) === 'igx-grid-summary-row' ;
@@ -433,17 +427,24 @@ export class IgxGridNavigationService {
433427 const rowIndex = selectedNode . row ;
434428 const visibleColumnIndex = selectedNode . column ;
435429 const isSummaryRow = selectedNode . isSummaryRow ;
430+ const nextIsDetailRow = rowIndex + 1 <= this . grid . dataView . length - 1 ?
431+ this . grid . isDetailRecord ( this . grid . dataView [ rowIndex + 1 ] ) : false ;
432+ const isLastColumn = this . grid . unpinnedColumns [ this . grid . unpinnedColumns . length - 1 ] . visibleIndex === visibleColumnIndex ;
436433 if ( isSummaryRow && rowIndex === 0 &&
437434 this . grid . unpinnedColumns [ this . grid . unpinnedColumns . length - 1 ] . visibleIndex === visibleColumnIndex ) {
438435 return ;
439436 }
437+ if ( nextIsDetailRow && isLastColumn ) {
438+ this . navigateDown ( currentRowEl , { row : rowIndex , column : visibleColumnIndex } ) ;
439+ return ;
440+ }
440441
441442 if ( this . isRowInEditMode ( rowIndex ) ) {
442443 this . moveNextEditable ( rowIndex , visibleColumnIndex ) ;
443444 return ;
444445 }
445446
446- if ( this . grid . unpinnedColumns [ this . grid . unpinnedColumns . length - 1 ] . visibleIndex === visibleColumnIndex ) {
447+ if ( isLastColumn ) {
447448 const rowEl = this . grid . rowList . find ( row => row . index === rowIndex + 1 ) ?
448449 this . grid . rowList . find ( row => row . index === rowIndex + 1 ) :
449450 this . grid . summariesRowList . find ( row => row . index === rowIndex + 1 ) ;
@@ -556,6 +557,24 @@ export class IgxGridNavigationService {
556557 return ;
557558 }
558559
560+ const prevIsDetailRow = rowIndex > 0 ? this . grid . isDetailRecord ( this . grid . dataView [ rowIndex - 1 ] ) : false ;
561+ if ( visibleColumnIndex === 0 && prevIsDetailRow ) {
562+ let target = currentRowEl . previousElementSibling ;
563+ const applyFocusFunc = ( ) => {
564+ target = this . getRowByIndex ( rowIndex - 1 , '' ) ;
565+ target . focus ( { preventScroll : true } ) ;
566+ } ;
567+ if ( target ) {
568+ applyFocusFunc ( ) ;
569+ } else {
570+ this . performVerticalScrollToCell ( rowIndex - 1 , visibleColumnIndex , ( ) => {
571+ applyFocusFunc ( ) ;
572+ } ) ;
573+ }
574+
575+ return ;
576+ }
577+
559578 if ( visibleColumnIndex === 0 ) {
560579 if ( rowIndex === 0 && this . grid . allowFiltering && this . grid . filterMode === FilterMode . quickFilter ) {
561580 this . moveFocusToFilterCell ( ) ;
@@ -576,13 +595,12 @@ export class IgxGridNavigationService {
576595
577596 public shouldPerformVerticalScroll ( targetRowIndex : number , visibleColumnIndex : number ) : boolean {
578597 const containerTopOffset = parseInt ( this . verticalDisplayContainerElement . style . top , 10 ) ;
579- const targetRow = this . grid . summariesRowList . filter ( s => s . index !== 0 )
580- . concat ( this . grid . rowList . toArray ( ) ) . find ( r => r . index === targetRowIndex ) ;
598+ const targetRow = this . getRowByIndex ( targetRowIndex , '' ) as any ;
581599 const rowHeight = this . grid . verticalScrollContainer . getSizeAt ( targetRowIndex ) ;
582600 const containerHeight = this . grid . calcHeight ? Math . ceil ( this . grid . calcHeight ) : 0 ;
583- const targetEndTopOffset = targetRow ? targetRow . nativeElement . offsetTop + rowHeight + containerTopOffset :
601+ const targetEndTopOffset = targetRow ? targetRow . offsetTop + rowHeight + containerTopOffset :
584602 containerHeight + rowHeight ;
585- if ( ! targetRow || targetRow . nativeElement . offsetTop < Math . abs ( containerTopOffset )
603+ if ( ! targetRow || targetRow . offsetTop < Math . abs ( containerTopOffset )
586604 || containerHeight && containerHeight < targetEndTopOffset ) {
587605 return true ;
588606 } else {
@@ -622,13 +640,18 @@ export class IgxGridNavigationService {
622640 }
623641
624642 protected getRowByIndex ( index , selector = this . getRowSelector ( ) ) {
625- return this . grid . nativeElement . querySelector (
626- `${ selector } [data-rowindex="${ index } "]` ) ;
627- }
643+ const gridTag = this . grid . nativeElement . tagName . toLocaleLowerCase ( ) ;
644+ const row = Array . from ( this . grid . tbody . nativeElement . querySelectorAll (
645+ `${ selector } [data-rowindex="${ index } "]` ) )
646+ . find ( x => this . getClosestElemByTag ( x , gridTag ) . getAttribute ( 'id' ) === this . grid . id ) ;
647+ return row ;
648+ }
628649
629650 protected getNextRowByIndex ( nextIndex ) {
630- return this . grid . tbody . nativeElement . querySelector (
631- `[data-rowindex="${ nextIndex } "]` ) ;
651+ const gridTag = this . grid . nativeElement . tagName . toLocaleLowerCase ( ) ;
652+ const row = Array . from ( this . grid . tbody . nativeElement . querySelectorAll (
653+ `[data-rowindex="${ nextIndex } "]` ) ) . find ( x => this . getClosestElemByTag ( x , gridTag ) . getAttribute ( 'id' ) === this . grid . id ) ;
654+ return row ;
632655 }
633656
634657 private getAllRows ( ) {
@@ -637,10 +660,24 @@ export class IgxGridNavigationService {
637660 }
638661
639662 protected getCellSelector ( visibleIndex ?: number , isSummary = false ) : string {
663+ if ( visibleIndex === 0 && this . grid . hasDetails && ! isSummary ) {
664+ return 'igx-expandable-grid-cell' ;
665+ }
640666 return isSummary ? 'igx-grid-summary-cell' : 'igx-grid-cell' ;
641667 }
642668
643669 protected getRowSelector ( ) : string {
644670 return 'igx-grid-row' ;
645671 }
672+
673+ protected getClosestElemByTag ( sourceElem , targetTag ) {
674+ let result = sourceElem ;
675+ while ( result !== null && result . nodeType === 1 ) {
676+ if ( result . tagName . toLowerCase ( ) === targetTag . toLowerCase ( ) ) {
677+ return result ;
678+ }
679+ result = result . parentNode ;
680+ }
681+ return null ;
682+ }
646683}
0 commit comments