@@ -8,20 +8,27 @@ interface ThreeTabsCompProps {
8
8
isMiddleDisabled ?: boolean ;
9
9
showDisableButton ?: boolean ;
10
10
disabledIndex ?: number ;
11
+ isVertical ?: boolean ;
11
12
}
12
13
13
14
const ThreeTabsComponent = component$ (
14
15
( {
15
16
isMiddleDisabled = false ,
16
17
showDisableButton = false ,
18
+ isVertical = false ,
17
19
disabledIndex,
18
20
} : ThreeTabsCompProps ) => {
19
21
const isMiddleDisabledSignal = useSignal ( isMiddleDisabled ) ;
20
22
21
23
return (
22
24
< >
23
- < Tabs data-testid = "tabs" >
24
- < TabList >
25
+ < Tabs data-testid = "tabs" vertical = { isVertical } >
26
+ < TabList
27
+ style = { {
28
+ display : 'flex' ,
29
+ flexDirection : isVertical ? 'column' : 'row' ,
30
+ } }
31
+ >
25
32
< Tab disabled = { disabledIndex === 0 } > Tab 1</ Tab >
26
33
< Tab disabled = { disabledIndex === 1 || isMiddleDisabledSignal . value } >
27
34
Tab 2
@@ -229,79 +236,165 @@ describe('Tabs', () => {
229
236
} ) ;
230
237
} ) ;
231
238
232
- describe ( 'Right key handling' , ( ) => {
233
- it ( `GIVEN 3 tabs and the focus is on the first,
234
- WHEN triggering the right arrow key
235
- THEN the focus should be on the next tab` , ( ) => {
236
- cy . mount ( < ThreeTabsComponent /> ) ;
239
+ describe ( 'Orientation: Horizontal' , ( ) => {
240
+ describe ( 'RIGHT key handling' , ( ) => {
241
+ it ( `GIVEN 3 tabs and the focus is on the first,
242
+ WHEN triggering the right arrow key
243
+ THEN the focus should be on the next tab` , ( ) => {
244
+ cy . mount ( < ThreeTabsComponent /> ) ;
237
245
238
- cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{rightarrow}' ) ;
246
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{rightarrow}' ) ;
239
247
240
- cy . findByRole ( 'tab' , { name : / T a b 2 / i } ) . should ( 'have.focus' ) ;
241
- } ) ;
248
+ cy . findByRole ( 'tab' , { name : / T a b 2 / i } ) . should ( 'have.focus' ) ;
249
+ } ) ;
242
250
243
- it ( `GIVEN 3 tabs and the focus is on the last,
244
- WHEN triggering the right arrow key
245
- THEN the focus should be on the first tab` , ( ) => {
246
- cy . mount ( < ThreeTabsComponent /> ) ;
251
+ it ( `GIVEN 3 tabs and the focus is on the last,
252
+ WHEN triggering the right arrow key
253
+ THEN the focus should be on the first tab` , ( ) => {
254
+ cy . mount ( < ThreeTabsComponent /> ) ;
247
255
248
- cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . type ( '{rightarrow}' ) ;
256
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . type ( '{rightarrow}' ) ;
249
257
250
- cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
251
- } ) ;
258
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
259
+ } ) ;
252
260
253
- it ( `GIVEN 3 tabs and the second is disabled and the focus is on the first,
254
- WHEN triggering the right arrow key
255
- THEN the focus should be on the third tab` , ( ) => {
256
- cy . mount ( < ThreeTabsComponent isMiddleDisabled = { true } /> ) ;
261
+ it ( `GIVEN 3 tabs and the second is disabled and the focus is on the first,
262
+ WHEN triggering the right arrow key
263
+ THEN the focus should be on the third tab` , ( ) => {
264
+ cy . mount ( < ThreeTabsComponent isMiddleDisabled = { true } /> ) ;
257
265
258
- cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{rightarrow}' ) ;
266
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{rightarrow}' ) ;
259
267
260
- cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . should ( 'have.focus' ) ;
268
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . should ( 'have.focus' ) ;
269
+ } ) ;
270
+
271
+ it ( `GIVEN 3 tabs and the focus is on the first,
272
+ WHEN disabling the middle dynamically and triggering the right arrow key
273
+ THEN the focus should be on the third tab` , ( ) => {
274
+ cy . mount ( < ThreeTabsComponent showDisableButton = { true } /> ) ;
275
+
276
+ cy . findByRole ( 'button' , { name : 'Toggle middle tab disabled' } ) . click ( ) ;
277
+
278
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{rightarrow}' ) ;
279
+
280
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . should ( 'have.focus' ) ;
281
+ } ) ;
261
282
} ) ;
262
283
263
- it ( `GIVEN 3 tabs and the focus is on the first,
264
- WHEN disabling the middle dynamically and triggering the right arrow key
265
- THEN the focus should be on the third tab` , ( ) => {
266
- cy . mount ( < ThreeTabsComponent showDisableButton = { true } /> ) ;
284
+ describe ( 'LEFT key handling' , ( ) => {
285
+ it ( `GIVEN 3 tabs and the focus is on the second,
286
+ WHEN triggering the left arrow key
287
+ THEN the focus should be on the first tab` , ( ) => {
288
+ cy . mount ( < ThreeTabsComponent /> ) ;
267
289
268
- cy . findByRole ( 'button ' , { name : 'Toggle middle tab disabled' } ) . click ( ) ;
290
+ cy . findByRole ( 'tab ' , { name : / T a b 2 / i } ) . type ( '{leftarrow}' ) ;
269
291
270
- cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{rightarrow}' ) ;
292
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
293
+ } ) ;
271
294
272
- cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . should ( 'have.focus' ) ;
295
+ it ( `GIVEN 3 tabs and the focus is on the first,
296
+ WHEN triggering the left arrow key
297
+ THEN the focus should be on the last tab` , ( ) => {
298
+ cy . mount ( < ThreeTabsComponent /> ) ;
299
+
300
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{leftarrow}' ) ;
301
+
302
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . should ( 'have.focus' ) ;
303
+ } ) ;
304
+
305
+ it ( `GIVEN 3 tabs and the second is disabled and the focus is on the third,
306
+ WHEN triggering the left arrow key
307
+ THEN the focus should be on the first tab` , ( ) => {
308
+ cy . mount ( < ThreeTabsComponent isMiddleDisabled = { true } /> ) ;
309
+
310
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . type ( '{leftarrow}' ) ;
311
+
312
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
313
+ } ) ;
273
314
} ) ;
274
315
} ) ;
275
316
276
- describe ( 'Left key handling' , ( ) => {
277
- it ( `GIVEN 3 tabs and the focus is on the second,
278
- WHEN triggering the left arrow key
279
- THEN the focus should be on the first tab` , ( ) => {
280
- cy . mount ( < ThreeTabsComponent /> ) ;
317
+ describe ( 'Orientation: Vertical' , ( ) => {
318
+ describe ( 'DOWN key handling' , ( ) => {
319
+ it ( `GIVEN 3 vertical tabs and the focus is on the first,
320
+ WHEN triggering the down arrow key
321
+ THEN the focus should be on the next tab` , ( ) => {
322
+ cy . mount ( < ThreeTabsComponent isVertical = { true } /> ) ;
281
323
282
- cy . findByRole ( 'tab' , { name : / T a b 2 / i } ) . type ( '{leftarrow }' ) ;
324
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{downarrow }' ) ;
283
325
284
- cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
285
- } ) ;
326
+ cy . findByRole ( 'tab' , { name : / T a b 2 / i } ) . should ( 'have.focus' ) ;
327
+ } ) ;
286
328
287
- it ( `GIVEN 3 tabs and the focus is on the first ,
288
- WHEN triggering the left arrow key
289
- THEN the focus should be on the last tab` , ( ) => {
290
- cy . mount ( < ThreeTabsComponent /> ) ;
329
+ it ( `GIVEN 3 vertical tabs and the focus is on the last ,
330
+ WHEN triggering the down arrow key
331
+ THEN the focus should be on the first tab` , ( ) => {
332
+ cy . mount ( < ThreeTabsComponent isVertical = { true } /> ) ;
291
333
292
- cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{leftarrow }' ) ;
334
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . type ( '{downarrow }' ) ;
293
335
294
- cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . should ( 'have.focus' ) ;
336
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
337
+ } ) ;
338
+
339
+ it ( `GIVEN 3 vertical tabs and the second is disabled and the focus is on the first,
340
+ WHEN triggering the down arrow key
341
+ THEN the focus should be on the third tab` , ( ) => {
342
+ cy . mount (
343
+ < ThreeTabsComponent isVertical = { true } isMiddleDisabled = { true } />
344
+ ) ;
345
+
346
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{downarrow}' ) ;
347
+
348
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . should ( 'have.focus' ) ;
349
+ } ) ;
350
+
351
+ it ( `GIVEN 3 vertical tabs and the focus is on the first,
352
+ WHEN disabling the middle dynamically and triggering the down arrow key
353
+ THEN the focus should be on the third tab` , ( ) => {
354
+ cy . mount (
355
+ < ThreeTabsComponent isVertical = { true } showDisableButton = { true } />
356
+ ) ;
357
+
358
+ cy . findByRole ( 'button' , { name : 'Toggle middle tab disabled' } ) . click ( ) ;
359
+
360
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{downarrow}' ) ;
361
+
362
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . should ( 'have.focus' ) ;
363
+ } ) ;
295
364
} ) ;
296
365
297
- it ( `GIVEN 3 tabs and the second is disabled and the focus is on the third,
298
- WHEN triggering the left arrow key
299
- THEN the focus should be on the first tab` , ( ) => {
300
- cy . mount ( < ThreeTabsComponent isMiddleDisabled = { true } /> ) ;
366
+ describe ( 'UP key handling' , ( ) => {
367
+ it ( `GIVEN 3 vertical tabs and the focus is on the second,
368
+ WHEN triggering the up arrow key
369
+ THEN the focus should be on the first tab` , ( ) => {
370
+ cy . mount ( < ThreeTabsComponent isVertical = { true } /> ) ;
301
371
302
- cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . type ( '{leftarrow }' ) ;
372
+ cy . findByRole ( 'tab' , { name : / T a b 2 / i } ) . type ( '{uparrow }' ) ;
303
373
304
- cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
374
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
375
+ } ) ;
376
+
377
+ it ( `GIVEN 3 vertical tabs and the focus is on the first,
378
+ WHEN triggering the up arrow key
379
+ THEN the focus should be on the last tab` , ( ) => {
380
+ cy . mount ( < ThreeTabsComponent isVertical = { true } /> ) ;
381
+
382
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . type ( '{uparrow}' ) ;
383
+
384
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . should ( 'have.focus' ) ;
385
+ } ) ;
386
+
387
+ it ( `GIVEN 3 vertical tabs and the second is disabled and the focus is on the third,
388
+ WHEN triggering the up arrow key
389
+ THEN the focus should be on the first tab` , ( ) => {
390
+ cy . mount (
391
+ < ThreeTabsComponent isVertical = { true } isMiddleDisabled = { true } />
392
+ ) ;
393
+
394
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . type ( '{uparrow}' ) ;
395
+
396
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
397
+ } ) ;
305
398
} ) ;
306
399
} ) ;
307
400
@@ -316,6 +409,16 @@ describe('Tabs', () => {
316
409
cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
317
410
} ) ;
318
411
412
+ it ( `GIVEN 3 vertical tabs and the focus is on the third,
413
+ WHEN triggering the 'home' key
414
+ THEN the focus should be on the first tab` , ( ) => {
415
+ cy . mount ( < ThreeTabsComponent isVertical = { true } /> ) ;
416
+
417
+ cy . findByRole ( 'tab' , { name : / T a b 3 / i } ) . type ( '{home}' ) ;
418
+
419
+ cy . findByRole ( 'tab' , { name : / T a b 1 / i } ) . should ( 'have.focus' ) ;
420
+ } ) ;
421
+
319
422
it ( `GIVEN 3 tabs and the first is disabled and the focus is on the third,
320
423
WHEN triggering the 'home' key
321
424
THEN the focus should be on the second tab` , ( ) => {
0 commit comments