Skip to content

Commit

Permalink
Tab aria selected (#1723)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
  • Loading branch information
OliverSpeir and delucis authored Apr 8, 2024
1 parent 418d386 commit 3b29b3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-onions-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fixes accessibility by using `aria-selected="false"` for inactive tabs instead of removing `aria-selected="true"` in the tablist of Starlight’s `<Tabs>` component
8 changes: 4 additions & 4 deletions packages/starlight/user-components/Tabs.astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { html, panels } = processPanels(panelHtml);
role="tab"
href={'#' + panelId}
id={tabId}
aria-selected={idx === 0 && 'true'}
aria-selected={idx === 0 ? 'true' : 'false'}
tabindex={idx !== 0 ? -1 : 0}
>
{icon && <Icon name={icon} />}
Expand Down Expand Up @@ -61,7 +61,7 @@ const { html, panels } = processPanels(panelHtml);
color: var(--sl-color-gray-3);
outline-offset: var(--sl-outline-offset-inside);
}
.tab [role='tab'][aria-selected] {
.tab [role='tab'][aria-selected="true"] {
color: var(--sl-color-white);
border-color: var(--sl-color-text-accent);
font-weight: 600;
Expand All @@ -87,7 +87,7 @@ const { html, panels } = processPanels(panelHtml);
// Handle clicks for mouse users
tab.addEventListener('click', (e) => {
e.preventDefault();
const currentTab = tablist.querySelector('[aria-selected]');
const currentTab = tablist.querySelector('[aria-selected="true"]');
if (e.currentTarget !== currentTab) {
this.switchTab(e.currentTarget as HTMLAnchorElement, i);
}
Expand Down Expand Up @@ -122,7 +122,7 @@ const { html, panels } = processPanels(panelHtml);

// Mark all tabs as unselected and hide all tab panels.
this.tabs.forEach((tab) => {
tab.removeAttribute('aria-selected');
tab.setAttribute('aria-selected', 'false');
tab.setAttribute('tabindex', '-1');
});
this.panels.forEach((oldPanel) => {
Expand Down

0 comments on commit 3b29b3a

Please sign in to comment.