@@ -8,6 +8,7 @@ const MOCK_DEFAULT_SLOT = 'Message Slot';
88const MOCK_GROUP_CONTEXT = {
99 disabled : false ,
1010 selected : '' ,
11+ focusedTabId : null ,
1112} ;
1213
1314const baseProps = {
@@ -388,5 +389,51 @@ describe('DtTab Tests', () => {
388389 expect ( tab . attributes ( 'tabindex' ) ) . toBe ( '-1' ) ;
389390 } ) ;
390391 } ) ;
392+
393+ describe ( 'Roving tabindex' , ( ) => {
394+ describe ( 'When focusedTabId matches this tab' , ( ) => {
395+ beforeEach ( ( ) => {
396+ mockProvide = { groupContext : { ...MOCK_GROUP_CONTEXT , selected : '' , focusedTabId : MOCK_ID } } ;
397+
398+ updateWrapper ( ) ;
399+ } ) ;
400+
401+ it ( 'tabindex should be 0' , ( ) => {
402+ expect ( tab . attributes ( 'tabindex' ) ) . toBe ( '0' ) ;
403+ } ) ;
404+
405+ it ( 'aria-selected should still be "false"' , ( ) => {
406+ expect ( tab . attributes ( 'aria-selected' ) ) . toBe ( 'false' ) ;
407+ } ) ;
408+ } ) ;
409+
410+ describe ( 'When focusedTabId is a different tab' , ( ) => {
411+ beforeEach ( ( ) => {
412+ mockProvide = { groupContext : { ...MOCK_GROUP_CONTEXT , selected : MOCK_PANEL_ID , focusedTabId : 'other-tab' } } ;
413+
414+ updateWrapper ( ) ;
415+ } ) ;
416+
417+ it ( 'tabindex should be -1 even when selected' , ( ) => {
418+ expect ( tab . attributes ( 'tabindex' ) ) . toBe ( '-1' ) ;
419+ } ) ;
420+
421+ it ( 'aria-selected should still be "true"' , ( ) => {
422+ expect ( tab . attributes ( 'aria-selected' ) ) . toBe ( 'true' ) ;
423+ } ) ;
424+ } ) ;
425+
426+ describe ( 'When focusedTabId is null' , ( ) => {
427+ beforeEach ( ( ) => {
428+ mockProvide = { groupContext : { ...MOCK_GROUP_CONTEXT , selected : MOCK_PANEL_ID , focusedTabId : null } } ;
429+
430+ updateWrapper ( ) ;
431+ } ) ;
432+
433+ it ( 'tabindex should fall back to selected tab' , ( ) => {
434+ expect ( tab . attributes ( 'tabindex' ) ) . toBe ( '0' ) ;
435+ } ) ;
436+ } ) ;
437+ } ) ;
391438 } ) ;
392439} ) ;
0 commit comments