@@ -885,49 +885,52 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
885885
886886 private _editingCellTabHandler ( eventArgs , direction ) {
887887 const eventTarget = eventArgs . originalEvent . target ;
888- let $cell = this . _getCellElementFromTarget ( eventTarget ) ;
889- let isEditingAllowed ;
890- const $event = eventArgs . originalEvent ;
891- const elementType = this . _getElementType ( eventTarget ) ;
888+ const $targetCell = this . _getCellElementFromTarget ( eventTarget ) ;
889+ const isCommandCell = $targetCell . is ( COMMAND_CELL_SELECTOR ) ;
892890
893- if ( $cell . is ( COMMAND_CELL_SELECTOR ) ) {
891+ if ( isCommandCell ) {
894892 return ! this . _targetCellTabHandler ( eventArgs , direction ) ;
895893 }
896894
897- this . _updateFocusedCellPosition ( $cell ) ;
895+ this . _updateFocusedCellPosition ( $targetCell ) ;
896+
897+ const elementType = this . _getElementType ( eventTarget ) ;
898898 const nextCellInfo = this . _getNextCellByTabKey (
899- $event ,
899+ eventArgs . originalEvent ,
900900 direction ,
901901 elementType ,
902902 ) ;
903- $cell = nextCellInfo . $cell ;
903+ const $nextCell = nextCellInfo . $cell ;
904904
905- if ( ! $cell || this . _handleTabKeyOnMasterDetailCell ( $cell , direction ) ) {
905+ if ( ! $nextCell || this . _handleTabKeyOnMasterDetailCell ( $nextCell , direction ) ) {
906906 return false ;
907907 }
908908
909- const column = this . _getColumnByCellElement ( $cell ) ;
910- const $row = $cell . parent ( ) ;
911- const rowIndex = this . _getRowIndex ( $row ) ;
912- const row = this . _dataController . items ( ) [ rowIndex ] as any ;
913- const editingController = this . _editingController ;
909+ let isEditingAllowed = false ;
910+ const column = this . _getColumnByCellElement ( $nextCell ) ;
914911
915- if ( column && column . allowEditing ) {
912+ if ( column ?. allowEditing ) {
913+ const $row = $nextCell . parent ( ) ;
914+ const rowIndex = this . _getLocalRowIndex ( $row ) ;
915+ const row = this . _dataController . items ( ) [ rowIndex ] as any ;
916916 const isDataRow = ! row || row . rowType === 'data' ;
917- isEditingAllowed = editingController . allowUpdating ( { row } )
918- ? isDataRow
919- : row && row . isNewRow ;
917+
918+ isEditingAllowed = this . _editingController . allowUpdating ( { row } )
919+ ? isDataRow : row ? .isNewRow ;
920920 }
921921
922922 if ( ! isEditingAllowed ) {
923923 this . _closeEditCell ( ) ;
924924 }
925925
926- if ( this . _focusCell ( $cell , ! nextCellInfo . isHighlighted ) ) {
927- if ( ! this . _isRowEditMode ( ) && isEditingAllowed ) {
926+ const nextCellFocused = this . _focusCell ( $nextCell , ! nextCellInfo . isHighlighted ) ;
927+
928+ if ( nextCellFocused ) {
929+ const isRowMode = this . _isRowEditMode ( ) ;
930+ if ( ! isRowMode && isEditingAllowed ) {
928931 this . _editFocusedCell ( ) ;
929932 } else {
930- this . _focusInteractiveElement ( $cell , eventArgs . shift ) ;
933+ this . _focusInteractiveElement ( $nextCell , eventArgs . shift ) ;
931934 }
932935 }
933936
@@ -2302,11 +2305,14 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
23022305 columnIndex : number ,
23032306 ) : void {
23042307 const $cell = this . _getFocusedCell ( ) ;
2305- const rowIndex = this . _getRowIndex ( $cell ?. parent ( ) ) ;
2308+ const $row = $cell ?. parent ( ) ;
2309+
2310+ const rowIndex = this . getRowIndex ( ) ;
23062311 const localRowIndex = Math . min (
2307- rowIndex - this . _dataController . getRowIndexOffset ( ) ,
2312+ this . _getLocalRowIndex ( $row ) ,
23082313 this . _dataController . items ( ) . length - 1 ,
23092314 ) ;
2315+
23102316 const isEditingCell = this . _editingController . isEditCell (
23112317 localRowIndex ,
23122318 columnIndex ,
@@ -2448,8 +2454,8 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
24482454 }
24492455 }
24502456
2451- protected _getRowIndex ( $row ) {
2452- let rowIndex = this . _rowsView . getRowIndex ( $row ) ;
2457+ protected _getRowIndex ( $row ) : number {
2458+ let rowIndex = this . _getLocalRowIndex ( $row ) ;
24532459
24542460 if ( rowIndex >= 0 ) {
24552461 rowIndex += this . _dataController . getRowIndexOffset ( ) ;
@@ -2458,6 +2464,12 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
24582464 return rowIndex ;
24592465 }
24602466
2467+ protected _getLocalRowIndex ( $row ) : number {
2468+ const rowIndex = this . _rowsView . getRowIndex ( $row ) ;
2469+
2470+ return rowIndex ;
2471+ }
2472+
24612473 protected getCellIndex ( $cell , rowIndex ) : number {
24622474 return this . _rowsView . getCellIndex ( $cell , rowIndex ) ;
24632475 }
0 commit comments