Skip to content

Commit 05e7c36

Browse files
committed
fix(tabs): ensure tablist is keyboard reachable when no active tab is defined
1 parent 88268d7 commit 05e7c36

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

projects/element-ng/tabs/si-tab-base.directive.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)