File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
src/aria/private/behaviors/grid Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -395,7 +395,7 @@ describe('Grid', () => {
395395 expect ( grid . focusBehavior . activeCoords ( ) ) . toEqual ( { row : 1 , col : 1 } ) ;
396396 } ) ;
397397
398- it ( 'should focus the first cell if active cell and coords are no longer valid ' , ( ) => {
398+ it ( 'should focus the row above when the last row is deleted ' , ( ) => {
399399 const cellsSignal = signal ( createTestGrid ( createGridA ) ) ;
400400 const grid = setupGrid ( cellsSignal ) ;
401401 grid . gotoCell ( cellsSignal ( ) [ 2 ] [ 2 ] ) ;
@@ -416,8 +416,8 @@ describe('Grid', () => {
416416 expect ( grid . focusBehavior . stateStale ( ) ) . toBe ( true ) ;
417417 const result = grid . resetState ( ) ;
418418 expect ( result ) . toBe ( true ) ;
419- expect ( grid . focusBehavior . activeCell ( ) ) . toBe ( newCells [ 0 ] [ 0 ] ) ;
420- expect ( grid . focusBehavior . activeCoords ( ) ) . toEqual ( { row : 0 , col : 0 } ) ;
419+ expect ( grid . focusBehavior . activeCell ( ) ) . toBe ( newCells [ 1 ] [ 1 ] ) ;
420+ expect ( grid . focusBehavior . activeCoords ( ) ) . toEqual ( { row : 1 , col : 1 } ) ;
421421 } ) ;
422422 } ) ;
423423} ) ;
Original file line number Diff line number Diff line change @@ -342,6 +342,18 @@ export class Grid<T extends GridCell> {
342342 return true ;
343343 }
344344
345+ // Try clamping the column as well.
346+ const colCount = this . data . getColCount ( targetRow ) ;
347+ if ( colCount !== undefined ) {
348+ const targetCol = Math . min ( activeCoords . col , colCount - 1 ) ;
349+ if (
350+ targetCol >= 0 &&
351+ this . focusBehavior . focusCoordinates ( { row : targetRow , col : targetCol } )
352+ ) {
353+ return true ;
354+ }
355+ }
356+
345357 // If that fails, try to find ANY cell in that row.
346358 const firstInRow = this . navigationBehavior . peekFirst ( targetRow ) ;
347359 if ( firstInRow !== undefined && this . focusBehavior . focusCoordinates ( firstInRow ) ) {
You can’t perform that action at this time.
0 commit comments