Skip to content

Commit acdde81

Browse files
committed
✨(frontend) fix toggle panel button a11y with dynamic label
improves screen sr by updating label and state indication dynamically Signed-off-by: Cyril <[email protected]>
1 parent 9b03754 commit acdde81

File tree

5 files changed

+42
-25
lines changed

5 files changed

+42
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to
1010

1111
- ♿(frontend) improve accessibility:
1212
- ♿(frontend) add skip to content button for keyboard accessibility #1624
13+
- ♿(frontend) fix toggle panel button a11y labels #1634
1314
- ⚡️(frontend) Enhance/html copy to download #1669
1415

1516
### Fixed
@@ -23,8 +24,6 @@ and this project adheres to
2324
- ✨ Add comments feature to the editor #1330
2425
- ✨(backend) Comments on text editor #1330
2526
- ✨(frontend) link to create new doc #1574
26-
- ♿(frontend) improve accessibility:
27-
- ♿(frontend) add skip to content button for keyboard accessibility #1624
2827

2928
### Fixed
3029

src/frontend/apps/e2e/__tests__/app-impress/doc-grid-dnd.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from '@playwright/test';
22

3-
import { createDoc, mockedListDocs } from './utils-common';
3+
import { createDoc, mockedListDocs, toggleHeaderMenu } from './utils-common';
44
import { createRootSubPage } from './utils-sub-pages';
55

66
test.describe('Doc grid dnd', () => {
@@ -185,10 +185,7 @@ test.describe('Doc grid dnd mobile', () => {
185185
true,
186186
);
187187

188-
await page
189-
.getByRole('button', { name: 'Open the header menu' })
190-
.getByText('menu')
191-
.click();
188+
await toggleHeaderMenu(page);
192189

193190
await expect(page.locator('.--docs-sub-page-item').first()).toHaveAttribute(
194191
'draggable',

src/frontend/apps/e2e/__tests__/app-impress/utils-common.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,34 @@ export const randomName = (name: string, browserName: string, length: number) =>
8383
return `${browserName}-${Math.floor(Math.random() * 10000)}-${index}-${name}`;
8484
});
8585

86+
export const openHeaderMenu = async (page: Page) => {
87+
const toggleButton = page.getByTestId('header-menu-toggle');
88+
await expect(toggleButton).toBeVisible();
89+
90+
const isExpanded =
91+
(await toggleButton.getAttribute('aria-expanded')) === 'true';
92+
if (!isExpanded) {
93+
await toggleButton.click();
94+
}
95+
};
96+
97+
export const closeHeaderMenu = async (page: Page) => {
98+
const toggleButton = page.getByTestId('header-menu-toggle');
99+
await expect(toggleButton).toBeVisible();
100+
101+
const isExpanded =
102+
(await toggleButton.getAttribute('aria-expanded')) === 'true';
103+
if (isExpanded) {
104+
await toggleButton.click();
105+
}
106+
};
107+
108+
export const toggleHeaderMenu = async (page: Page) => {
109+
const toggleButton = page.getByTestId('header-menu-toggle');
110+
await expect(toggleButton).toBeVisible();
111+
await toggleButton.click();
112+
};
113+
86114
export const createDoc = async (
87115
page: Page,
88116
docName: string,
@@ -94,10 +122,7 @@ export const createDoc = async (
94122

95123
for (let i = 0; i < randomDocs.length; i++) {
96124
if (isMobile) {
97-
await page
98-
.getByRole('button', { name: 'Open the header menu' })
99-
.getByText('menu')
100-
.click();
125+
await openHeaderMenu(page);
101126
}
102127

103128
await page

src/frontend/apps/e2e/__tests__/app-impress/utils-sub-pages.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Page, expect } from '@playwright/test';
22

33
import {
44
BrowserName,
5+
closeHeaderMenu,
6+
openHeaderMenu,
57
randomName,
68
updateDocTitle,
79
verifyDocName,
@@ -15,10 +17,7 @@ export const createRootSubPage = async (
1517
isMobile = false,
1618
) => {
1719
if (isMobile) {
18-
await page
19-
.getByRole('button', { name: 'Open the header menu' })
20-
.getByText('menu')
21-
.click();
20+
await openHeaderMenu(page);
2221
}
2322

2423
// Get response
@@ -29,10 +28,7 @@ export const createRootSubPage = async (
2928
const subPageJson = (await response.json()) as { id: string };
3029

3130
if (isMobile) {
32-
await page
33-
.getByRole('button', { name: 'Open the header menu' })
34-
.getByText('menu')
35-
.click();
31+
await openHeaderMenu(page);
3632
}
3733

3834
// Get doc tree
@@ -44,13 +40,9 @@ export const createRootSubPage = async (
4440
.getByTestId(`doc-sub-page-item-${subPageJson.id}`)
4541
.first();
4642
await expect(subPageItem).toBeVisible();
47-
await subPageItem.click();
4843

4944
if (isMobile) {
50-
await page
51-
.getByRole('button', { name: 'Open the header menu' })
52-
.getByText('close')
53-
.click();
45+
await closeHeaderMenu(page);
5446
}
5547

5648
// Update sub page name

src/frontend/apps/impress/src/features/header/components/ButtonTogglePanel.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ export const ButtonTogglePanel = () => {
1212
<Button
1313
size="medium"
1414
onClick={() => togglePanel()}
15-
aria-label={t('Open the header menu')}
15+
aria-label={t(
16+
isPanelOpen ? 'Close the header menu' : 'Open the header menu',
17+
)}
18+
aria-expanded={isPanelOpen}
1619
variant="tertiary"
1720
icon={
1821
<Icon $withThemeInherited iconName={isPanelOpen ? 'close' : 'menu'} />
1922
}
2023
className="--docs--button-toggle-panel"
24+
data-testid="header-menu-toggle"
2125
/>
2226
);
2327
};

0 commit comments

Comments
 (0)