Skip to content

Commit db1be38

Browse files
CopilotIEvangelist
andauthored
fix: add aria-pressed to toggle buttons for screen reader accessibility (#555)
* Initial plan * fix: Add aria-pressed to toggle buttons for screen reader accessibility (WCAG 4.1.2) Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com>
1 parent 7452f9f commit db1be38

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/frontend/src/components/AppHostBuilder.astro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ builder.Build().Run();`,
455455
data-toggle="frontend"
456456
data-tooltip-placement="top"
457457
title={Astro.locals.t('appHostBuilder.frontendTooltip')}
458+
aria-pressed="true"
458459
>
459460
<Icon name="laptop" size="1.2rem" />
460461
<span>Front end</span>
@@ -465,6 +466,7 @@ builder.Build().Run();`,
465466
data-toggle="database"
466467
data-tooltip-placement="top"
467468
title={Astro.locals.t('appHostBuilder.databaseTooltip')}
469+
aria-pressed="false"
468470
>
469471
<Icon name="seti:db" size="1.2rem" />
470472
<span>{Astro.locals.t('appHostBuilder.database')}</span>
@@ -475,6 +477,7 @@ builder.Build().Run();`,
475477
data-toggle="api"
476478
data-tooltip-placement="top"
477479
title={Astro.locals.t('appHostBuilder.apiTooltip')}
480+
aria-pressed="false"
478481
>
479482
<Icon name="seti:json" size="1.2rem" />
480483
<span>{Astro.locals.t('appHostBuilder.api')}</span>
@@ -485,6 +488,7 @@ builder.Build().Run();`,
485488
data-toggle="container"
486489
data-tooltip-placement="top"
487490
title={Astro.locals.t('appHostBuilder.containerTooltip')}
491+
aria-pressed="false"
488492
>
489493
<Icon name="seti:docker" size="1.2rem" />
490494
<span>{Astro.locals.t('appHostBuilder.container')}</span>
@@ -495,6 +499,7 @@ builder.Build().Run();`,
495499
data-toggle="deployment"
496500
data-tooltip-placement="top"
497501
title={Astro.locals.t('appHostBuilder.deploymentTooltip')}
502+
aria-pressed="false"
498503
>
499504
<Icon name="rocket" size="1.2rem" />
500505
<span>{Astro.locals.t('appHostBuilder.deploy')}</span>
@@ -717,6 +722,7 @@ builder.Build().Run();`,
717722
toggleButtons.forEach((button) => {
718723
button.addEventListener('click', () => {
719724
button.classList.toggle('active');
725+
button.setAttribute('aria-pressed', button.classList.contains('active').toString());
720726
updateCodeDisplay();
721727
});
722728
});

src/frontend/src/components/LocalVsProdEnvironments.astro

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { Code } from '@astrojs/starlight/components';
55
<div class="orbit-section">
66
<div class="environment-toggle">
77
<div class="toggle-container">
8-
<button class="active toggle-btn toggle-local">
8+
<button class="active toggle-btn toggle-local" aria-pressed="true">
99
{Astro.locals.t('landing.environments.local')}
1010
</button>
11-
<button class="toggle-btn toggle-test">
11+
<button class="toggle-btn toggle-test" aria-pressed="false">
1212
{Astro.locals.t('landing.environments.test')}
1313
</button>
14-
<button class="toggle-btn toggle-prod">
14+
<button class="toggle-btn toggle-prod" aria-pressed="false">
1515
{Astro.locals.t('landing.environments.prod')}
1616
</button>
1717
</div>
@@ -183,10 +183,15 @@ import { Code } from '@astrojs/starlight/components';
183183
return isMobileUA || (isSmallScreen && hasTouch);
184184
}
185185

186+
function setActiveEnvironment(activeBtn) {
187+
[localBtn, testBtn, prodBtn].forEach((btn) => {
188+
btn.setAttribute('aria-pressed', (btn === activeBtn).toString());
189+
btn.classList.toggle('active', btn === activeBtn);
190+
});
191+
}
192+
186193
localBtn.addEventListener('click', () => {
187-
localBtn.classList.add('active');
188-
testBtn.classList.remove('active');
189-
prodBtn.classList.remove('active');
194+
setActiveEnvironment(localBtn);
190195
container.classList.remove('test-active', 'prod-active');
191196
container.classList.add('local-active');
192197
localSubtitle.classList.add('local-active');
@@ -196,9 +201,7 @@ import { Code } from '@astrojs/starlight/components';
196201
});
197202

198203
testBtn.addEventListener('click', () => {
199-
testBtn.classList.add('active');
200-
localBtn.classList.remove('active');
201-
prodBtn.classList.remove('active');
204+
setActiveEnvironment(testBtn);
202205
container.classList.remove('local-active', 'prod-active');
203206
container.classList.add('test-active');
204207
testSubtitle.classList.add('test-active');
@@ -208,9 +211,7 @@ import { Code } from '@astrojs/starlight/components';
208211
});
209212

210213
prodBtn.addEventListener('click', () => {
211-
prodBtn.classList.add('active');
212-
localBtn.classList.remove('active');
213-
testBtn.classList.remove('active');
214+
setActiveEnvironment(prodBtn);
214215
container.classList.remove('local-active', 'test-active');
215216
container.classList.add('prod-active');
216217
prodSubtitle.classList.add('prod-active');

0 commit comments

Comments
 (0)