Skip to content

Commit 157d20f

Browse files
committed
fix(tabs): ensure tablist is keyboard reachable when no active tab is defined
1 parent adc3e41 commit 157d20f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

projects/element-ng/tabs/si-tabset.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { SiResizeObserverModule } from '@siemens/element-ng/resize-observer';
2929
import { SiTabBadgeComponent } from './si-tab-badge.component';
3030
import { SiTabBaseDirective } from './si-tab-base.directive';
3131
import { SiTabLinkComponent } from './si-tab-link.component';
32+
import { SiTabComponent } from './si-tab.component';
3233
import { SI_TABSET } from './si-tabs-tokens';
3334

3435
/**
@@ -94,6 +95,16 @@ export class SiTabsetComponent {
9495
}
9596

9697
constructor() {
98+
// Per the ARIA tabs pattern, at least one tab should be active. If the app
99+
// does not provide an active tab, activate the first non-disabled content
100+
// tab so the tablist stays keyboard reachable.
101+
effect(() => {
102+
const tabs = this.tabPanels();
103+
if (tabs.length && !tabs.some(tab => tab.active())) {
104+
tabs.find(tab => tab instanceof SiTabComponent && !tab.disabledTab())?.selectTab();
105+
}
106+
});
107+
97108
effect(() => {
98109
if (this.showMenuButton() && this.activeTab()) {
99110
// wait for menu button to render on DOM

0 commit comments

Comments
 (0)