-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(menu): added focus trapping, improved compatibility with screen r…
…eaders (#24076) * fix(menu): add basic accessibility features * fix(menu): add focus trapping * test(menu): add test for focus trapping * style(menu): lint fixes * fix(menu): focus first element inside instead of whole menu * test(menu): fix focus trap test to account for new behavior * refactor(menu): pull focus handler into its own prop * test(menu): add a11y testing * fix(menu): prevent nested aria landmark from header inside menu * fix(menu): revert switch to nav element * fix(menu): remove unnecessary import from test * fix(menu): allow for custom aria-label * fix(menu): move nested ARIA role logic to header for flexibility * fix(item): only add focusable class if it actually is focusable * fix(menu): allow focusing of menu itself, for a11y on menus with no focusable children * fix(item): move isFocusable logic to state for better reactivity * perf(item): only grab one focusable child * fix(menu): hide page content from screen readers when menu is open * fix(menu): fallback to focusing host element * docs(menu): add comments Co-authored-by: Liam DeBeasi <[email protected]>
- Loading branch information
1 parent
2916810
commit bdb268a
Showing
7 changed files
with
224 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
import { AxePuppeteer } from '@axe-core/puppeteer'; | ||
|
||
test('menu: axe', async () => { | ||
const page = await newE2EPage({ | ||
url: '/src/components/menu/test/a11y?ionic:_testing=true' | ||
}); | ||
|
||
const menu = await page.find('ion-menu'); | ||
await menu.callMethod('open'); | ||
await menu.waitForVisible(); | ||
|
||
const results = await new AxePuppeteer(page).analyze(); | ||
expect(results.violations.length).toEqual(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Segment - a11y</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"> | ||
<link href="../../../../../css/core.css" rel="stylesheet"> | ||
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet"> | ||
<script src="../../../../../scripts/testing/scripts.js"></script> | ||
<script nomodule src="../../../../../dist/ionic/ionic.js"></script> | ||
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script> | ||
</head> | ||
|
||
<body> | ||
<main> | ||
<h1>Menu</h1> | ||
<ion-menu menu-id="menu" content-id="main-content"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Menu</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<ion-list> | ||
<ion-item> | ||
<ion-button>Button</ion-button> | ||
</ion-item> | ||
<ion-item> | ||
<ion-button>Button 2</ion-button> | ||
</ion-item> | ||
<ion-item>Menu Item</ion-item> | ||
<ion-item>Menu Item</ion-item> | ||
<ion-item>Menu Item</ion-item> | ||
</ion-list> | ||
</ion-content> | ||
</ion-menu> | ||
</main> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.