@@ -177,6 +177,19 @@ describe('GridNavigation', () => {
177177
178178 expect ( nextCoords ) . toBeUndefined ( ) ;
179179 } ) ;
180+
181+ it ( 'should get disabled cells when allowDisabled is true and softDisabled is false' , ( ) => {
182+ const { gridNav, gridFocus} = setupGridNavigation ( signal ( cells ) , {
183+ softDisabled : signal ( false ) ,
184+ } ) ;
185+ gridNav . gotoCoords ( { row : 1 , col : 0 } ) ;
186+ cells [ 0 ] [ 0 ] . disabled . set ( true ) ;
187+
188+ const nextCoords = gridNav . peek ( direction . Up , gridFocus . activeCoords ( ) , 'nowrap' , true ) ;
189+
190+ expect ( nextCoords ) . toEqual ( { row : 0 , col : 0 } ) ;
191+ expect ( gridNav . peek ( direction . Up , gridFocus . activeCoords ( ) , 'nowrap' ) ) . toBeUndefined ( ) ;
192+ } ) ;
180193 } ) ;
181194
182195 describe ( 'down' , ( ) => {
@@ -216,6 +229,19 @@ describe('GridNavigation', () => {
216229
217230 expect ( nextCoords ) . toBeUndefined ( ) ;
218231 } ) ;
232+
233+ it ( 'should get disabled cells when allowDisabled is true and softDisabled is false' , ( ) => {
234+ const { gridNav, gridFocus} = setupGridNavigation ( signal ( cells ) , {
235+ softDisabled : signal ( false ) ,
236+ } ) ;
237+ gridNav . gotoCoords ( { row : 1 , col : 0 } ) ;
238+ cells [ 2 ] [ 0 ] . disabled . set ( true ) ;
239+
240+ const nextCoords = gridNav . peek ( direction . Down , gridFocus . activeCoords ( ) , 'nowrap' , true ) ;
241+
242+ expect ( nextCoords ) . toEqual ( { row : 2 , col : 0 } ) ;
243+ expect ( gridNav . peek ( direction . Down , gridFocus . activeCoords ( ) , 'nowrap' ) ) . toBeUndefined ( ) ;
244+ } ) ;
219245 } ) ;
220246
221247 describe ( 'left' , ( ) => {
@@ -237,9 +263,7 @@ describe('GridNavigation', () => {
237263 } ) ;
238264
239265 it ( 'should return the next coordinates even if all cells are disabled' , ( ) => {
240- cells . flat ( ) . forEach ( function ( cell ) {
241- cell . disabled . set ( true ) ;
242- } ) ;
266+ cells . flat ( ) . forEach ( c => c . disabled . set ( true ) ) ;
243267 gridNav . gotoCoords ( { row : 1 , col : 0 } ) ;
244268
245269 const nextCoords = gridNav . peek ( direction . Left , gridFocus . activeCoords ( ) ) ;
@@ -257,6 +281,19 @@ describe('GridNavigation', () => {
257281
258282 expect ( nextCoords ) . toBeUndefined ( ) ;
259283 } ) ;
284+
285+ it ( 'should get disabled cells when allowDisabled is true when softDisabled is false' , ( ) => {
286+ const { gridNav, gridFocus} = setupGridNavigation ( signal ( cells ) , {
287+ softDisabled : signal ( false ) ,
288+ } ) ;
289+ gridNav . gotoCoords ( { row : 0 , col : 1 } ) ;
290+ cells [ 0 ] [ 0 ] . disabled . set ( true ) ;
291+
292+ const nextCoords = gridNav . peek ( direction . Left , gridFocus . activeCoords ( ) , 'nowrap' , true ) ;
293+
294+ expect ( nextCoords ) . toEqual ( { row : 0 , col : 0 } ) ;
295+ expect ( gridNav . peek ( direction . Left , gridFocus . activeCoords ( ) , 'nowrap' ) ) . toBeUndefined ( ) ;
296+ } ) ;
260297 } ) ;
261298
262299 describe ( 'right' , ( ) => {
@@ -278,9 +315,7 @@ describe('GridNavigation', () => {
278315 } ) ;
279316
280317 it ( 'should return the next coordinates even if all cells are disabled' , ( ) => {
281- cells . flat ( ) . forEach ( function ( cell ) {
282- cell . disabled . set ( true ) ;
283- } ) ;
318+ cells . flat ( ) . forEach ( c => c . disabled . set ( true ) ) ;
284319 gridNav . gotoCoords ( { row : 1 , col : 0 } ) ;
285320
286321 const nextCoords = gridNav . peek ( direction . Right , gridFocus . activeCoords ( ) ) ;
@@ -298,6 +333,19 @@ describe('GridNavigation', () => {
298333
299334 expect ( nextCoords ) . toBeUndefined ( ) ;
300335 } ) ;
336+
337+ it ( 'should get disabled cells when allowDisabled is true and softDisabled is false' , ( ) => {
338+ const { gridNav, gridFocus} = setupGridNavigation ( signal ( cells ) , {
339+ softDisabled : signal ( false ) ,
340+ } ) ;
341+ gridNav . gotoCoords ( { row : 0 , col : 1 } ) ;
342+ cells [ 0 ] [ 2 ] . disabled . set ( true ) ;
343+
344+ const nextCoords = gridNav . peek ( direction . Right , gridFocus . activeCoords ( ) , 'nowrap' , true ) ;
345+
346+ expect ( nextCoords ) . toEqual ( { row : 0 , col : 2 } ) ;
347+ expect ( gridNav . peek ( direction . Right , gridFocus . activeCoords ( ) , 'nowrap' ) ) . toBeUndefined ( ) ;
348+ } ) ;
301349 } ) ;
302350 } ) ;
303351
@@ -1971,6 +2019,17 @@ describe('GridNavigation', () => {
19712019 expect ( gridFocus . activeCell ( ) ) . toBe ( cells [ 1 ] [ 0 ] ) ;
19722020 expect ( gridFocus . activeCoords ( ) ) . toEqual ( { row : 1 , col : 0 } ) ;
19732021 } ) ;
2022+
2023+ it ( 'should get disabled cells when allowDisabled is true and softDisabled is false' , ( ) => {
2024+ const cells = createTestGrid ( createGridA ) ;
2025+ const { gridNav} = setupGridNavigation ( signal ( cells ) , { softDisabled : signal ( false ) } ) ;
2026+ cells [ 0 ] [ 0 ] . disabled . set ( true ) ;
2027+
2028+ const firstCoords = gridNav . peekFirst ( undefined , true ) ;
2029+
2030+ expect ( firstCoords ) . toEqual ( { row : 0 , col : 0 } ) ;
2031+ expect ( gridNav . peekFirst ( ) ) . toEqual ( { row : 0 , col : 1 } ) ;
2032+ } ) ;
19742033 } ) ;
19752034
19762035 describe ( 'last/peekLast' , ( ) => {
@@ -2049,5 +2108,16 @@ describe('GridNavigation', () => {
20492108 expect ( gridFocus . activeCell ( ) ! . id ( ) ) . toBe ( 'cell-1-3' ) ;
20502109 expect ( gridFocus . activeCoords ( ) ) . toEqual ( { row : 1 , col : 3 } ) ;
20512110 } ) ;
2111+
2112+ it ( 'should get disabled cells when allowDisabled is true and softDisabled is false' , ( ) => {
2113+ const cells = createTestGrid ( createGridA ) ;
2114+ const { gridNav} = setupGridNavigation ( signal ( cells ) , { softDisabled : signal ( false ) } ) ;
2115+ cells [ 2 ] [ 2 ] . disabled . set ( true ) ;
2116+
2117+ const lastCoords = gridNav . peekLast ( undefined , true ) ;
2118+
2119+ expect ( lastCoords ) . toEqual ( { row : 2 , col : 2 } ) ;
2120+ expect ( gridNav . peekLast ( ) ) . toEqual ( { row : 2 , col : 1 } ) ;
2121+ } ) ;
20522122 } ) ;
20532123} ) ;
0 commit comments