Repository navigation
Description
Is this a regression?
No
Description
In @angular/aria/tabs, when selectedTab on ngTabList is changed programmatically after the user has interacted with the tab list, the roving tab stop (tabindex="0") stays on the previously active tab. It does not move to the newly selected tab.
TabListPattern.setDefaultStateEffect() puts the active item on the selected tab only while hasBeenInteracted() is false. After a single click or keydown on the tab list it returns early. Nothing else in the public API moves the active item: TabList exposes selectedTab, open(value) and findTab(value), but no goto/active-item setter. The only way to fix the tab stop is to write tabList._pattern.inputs.activeItem directly.
This comes up whenever the selection is driven from outside the tab strip, for example by router state (browser Back/Forward), deep links, or a "jump to section" control elsewhere on the page.
The Listbox has the same gap in roving mode: gotoIndex() always calls element.focus(), so there is no public way to move the active item without taking focus.
Reproduction
@Component({
imports: [Tabs, TabList, Tab, TabPanel, TabContent],
template: `
<div ngTabs>
<div ngTabList [(selectedTab)]="selected">
<div ngTab value="a">A</div>
<div ngTab value="b">B</div>
<div ngTab value="c">C</div>
</div>
<!-- panels omitted -->
</div>
<button (click)="selected.set('c')">Select C from outside</button>
`,
})
export class Repro {
readonly selected = signal<string | undefined>('a');
}- Click tab B, which marks the list as interacted.
- Click Select C from outside.
- Press Shift+Tab or Tab to move focus back into the tab list.
Expected Behavior
Focus lands on tab C, the selected tab. The WAI-ARIA APG tabs pattern says that when focus moves into the tab list, it goes to the active tab element. After step 2, tab C has tabindex="0".
Actual Behavior
Focus lands on tab B. Tab B keeps tabindex="0", and the selected tab C has tabindex="-1".
Environment
- Angular: 22.2.6
- CDK/Material:
@angular/aria22.2.7 - Browser(s): not browser-specific (state logic in
TabListPattern) - Operating System (e.g. Windows, macOS, Ubuntu): any
A possible fix is to have the tab list re-sync activeItem to the selected tab whenever selectedTab changes and focus is not inside the list. Another is a public method to move the active item without focusing, such as a focusElement: false option on a public goto.
Activity
fix(aria/tabs): keep roving tabindex in sync when active tab changes …
fix(aria/tabs): keep roving tabindex in sync when active tab changes …
fix(aria/tabs): keep roving tabindex in sync when active tab changes …
fix(aria/tabs): keep roving tabindex in sync when active tab changes …