@@ -36,7 +36,7 @@ import { SI_TABSET } from './si-tabs-tokens';
3636 '[attr.id]' : "'tab-' + tabId" ,
3737 '[attr.aria-selected]' : 'active()' ,
3838 '[attr.aria-disabled]' : 'disabledTab()' ,
39- '[attr.tabindex]' : 'tabset.focusKeyManager.activeItem === this && !disabledTab() ? 0 : -1 ' ,
39+ '[attr.tabindex]' : 'tabindexValue() ' ,
4040 '[attr.aria-controls]' : "'content-' + tabId" ,
4141 '(keydown.delete)' : 'closeTab($event)'
4242 }
@@ -97,6 +97,22 @@ export abstract class SiTabBaseDirective implements OnDestroy, FocusableOption {
9797 protected tabset = inject ( SI_TABSET ) ;
9898 private readonly index = computed ( ( ) => this . tabset . tabPanels ( ) . indexOf ( this ) ) ;
9999
100+ protected tabindexValue ( ) : number {
101+ if ( this . disabledTab ( ) ) return - 1 ;
102+
103+ const activeItem = this . tabset . focusKeyManager . activeItem ;
104+ if ( activeItem ) {
105+ return activeItem === this ? 0 : - 1 ;
106+ }
107+
108+ // If no tab is active and no item is focused in the key manager,
109+ // make the first non-disabled tab reachable via keyboard.
110+ if ( ! this . tabset . activeTab ( ) && this . tabset . tabPanels ( ) . find ( t => ! t . disabledTab ( ) ) === this )
111+ return 0 ;
112+
113+ return - 1 ;
114+ }
115+
100116 constructor ( ) {
101117 // Update the focusKeyManager if a tab is added that is active or if the tab is set active by the app.
102118 // This effect should not run, if active was already applied to the focusKeyManager.
0 commit comments