Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab aria selected #1723

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
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
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
Loading