Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions projects/element-ng/tabs/si-tabset.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
INJECTOR,
input,
signal,
untracked,
viewChild
} from '@angular/core';
import { RouterLink } from '@angular/router';
Expand All @@ -29,6 +30,7 @@ import { SiResizeObserverModule } from '@siemens/element-ng/resize-observer';
import { SiTabBadgeComponent } from './si-tab-badge.component';
import { SiTabBaseDirective } from './si-tab-base.directive';
import { SiTabLinkComponent } from './si-tab-link.component';
import { SiTabComponent } from './si-tab.component';
import { SI_TABSET } from './si-tabs-tokens';

/**
Expand Down Expand Up @@ -94,6 +96,30 @@ export class SiTabsetComponent {
}

constructor() {
// Per the ARIA tabs pattern, at least one tab should be active. If the app
// does not provide an active tab, activate the first non-disabled content
// tab so the tablist stays keyboard reachable.
effect(() => {
const tabs = this.tabPanels();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a subscription to this? I guess you can move it inside untracked

const hasActiveTab = !!this.activeTab();
untracked(() => {
if (hasActiveTab) {
return;
}
const tabToActivate = tabs.find(tab => {
if (tab.disabledTab()) {
return false;
}
if (tab instanceof SiTabComponent) {
const canActivate = tab.canActivate();
return canActivate ? canActivate() : true;
}
return true;
});
tabToActivate?.selectTab();
});
});

effect(() => {
if (this.showMenuButton() && this.activeTab()) {
// wait for menu button to render on DOM
Expand Down
Loading