-
Notifications
You must be signed in to change notification settings - Fork 13.5k
fix(action-sheet): add aria-labelledby #25837
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
57 changes: 57 additions & 0 deletions
57
core/src/components/action-sheet/test/a11y/action-sheet.e2e.ts
This file contains hidden or 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,57 @@ | ||
import AxeBuilder from '@axe-core/playwright'; | ||
import { expect } from '@playwright/test'; | ||
import type { E2EPage } from '@utils/test/playwright'; | ||
import { test } from '@utils/test/playwright'; | ||
|
||
const testAria = async (page: E2EPage, buttonID: string, expectedAriaLabelledBy: string | null) => { | ||
const didPresent = await page.spyOnEvent('ionActionSheetDidPresent'); | ||
const button = page.locator(`#${buttonID}`); | ||
|
||
await button.click(); | ||
await didPresent.next(); | ||
|
||
const alert = page.locator('ion-action-sheet'); | ||
|
||
/** | ||
* expect().toHaveAttribute() can't check for a null value, so grab and check | ||
* the value manually instead. | ||
*/ | ||
const ariaLabelledBy = await alert.getAttribute('aria-labelledby'); | ||
|
||
expect(ariaLabelledBy).toBe(expectedAriaLabelledBy); | ||
}; | ||
|
||
test.describe('action-sheet: a11y', () => { | ||
test.beforeEach(async ({ page, skip }) => { | ||
skip.rtl(); | ||
await page.goto(`/src/components/action-sheet/test/a11y`); | ||
}); | ||
|
||
test('should not have accessibility violations when header is defined', async ({ page }) => { | ||
const button = page.locator('#bothHeaders'); | ||
const didPresent = await page.spyOnEvent('ionActionSheetDidPresent'); | ||
|
||
await button.click(); | ||
await didPresent.next(); | ||
|
||
/** | ||
* action-sheet overlays the entire screen, so | ||
* Axe will be unable to verify color contrast | ||
* on elements under the backdrop. | ||
*/ | ||
const results = await new AxeBuilder({ page }).disableRules('color-contrast').analyze(); | ||
expect(results.violations).toEqual([]); | ||
}); | ||
|
||
test('should have aria-labelledby when header is set', async ({ page }) => { | ||
await testAria(page, 'bothHeaders', 'action-sheet-1-header'); | ||
}); | ||
|
||
test('should not have aria-labelledby when header is not set', async ({ page }) => { | ||
await testAria(page, 'noHeaders', null); | ||
}); | ||
|
||
test('should allow for manually specifying aria attributes', async ({ page }) => { | ||
await testAria(page, 'customAria', 'Custom title'); | ||
}); | ||
}); |
This file contains hidden or 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,68 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Action Sheet - A11y</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" /> | ||
<link href="../../../../../css/ionic.bundle.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> | ||
<script type="module"> | ||
import { actionSheetController } from '../../../../dist/ionic/index.esm.js'; | ||
window.actionSheetController = actionSheetController; | ||
</script> | ||
|
||
<body> | ||
<main class="ion-padding"> | ||
<h1>Action Sheet - A11y</h1> | ||
|
||
<ion-button id="bothHeaders" expand="block" onclick="presentBothHeaders()">Both Headers</ion-button> | ||
<ion-button id="subHeaderOnly" expand="block" onclick="presentSubHeaderOnly()">Subheader Only</ion-button> | ||
<ion-button id="noHeaders" expand="block" onclick="presentNoHeaders()">No Headers</ion-button> | ||
<ion-button id="customAria" expand="block" onclick="presentCustomAria()">Custom Aria</ion-button> | ||
</main> | ||
|
||
<script> | ||
async function openActionSheet(opts) { | ||
const actionSheet = await actionSheetController.create(opts); | ||
await actionSheet.present(); | ||
} | ||
|
||
function presentBothHeaders() { | ||
openActionSheet({ | ||
header: 'Header', | ||
subHeader: 'Subtitle', | ||
buttons: ['Confirm'], | ||
}); | ||
} | ||
|
||
function presentSubHeaderOnly() { | ||
openActionSheet({ | ||
subHeader: 'Subtitle', | ||
buttons: ['Confirm'], | ||
}); | ||
} | ||
|
||
function presentNoHeaders() { | ||
openActionSheet({ | ||
buttons: ['Confirm'], | ||
}); | ||
} | ||
|
||
function presentCustomAria() { | ||
openActionSheet({ | ||
header: 'Header', | ||
subHeader: 'Subtitle', | ||
buttons: ['Confirm'], | ||
htmlAttributes: { | ||
'aria-labelledby': 'Custom title', | ||
'aria-describedby': 'Custom description', | ||
}, | ||
}); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.