-
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(content): allow custom roles and aria attributes to be set on con…
…tent (#29753) Issue number: N/A --------- ## What is the current behavior? Setting a custom `role` on the `ion-content` element does not work. ## What is the new behavior? - Inherit attributes for the content element which allows a custom `role` property to be set - Adds e2e tests for content, header, and footer verifying that the proper roles are assigned ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information To test this PR: 1. Switch to the branch and navigate to the `core/` directory 1. Make sure to run `npx playwright install` if it has not been updated recenly 1. Run `npm run test.e2e src/components/content/test/a11y/` 1. Verify that the tests pass 1. Remove my fix in `core/src/components/content/content.tsx` and run the test again 1. Verify that the `should allow for custom role` tests fail
- Loading branch information
1 parent
ab4f279
commit 7b16397
Showing
4 changed files
with
151 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { expect } from '@playwright/test'; | ||
import { configs, test } from '@utils/test/playwright'; | ||
|
||
/** | ||
* Content does not have mode-specific styling | ||
*/ | ||
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => { | ||
test.describe(title('content: a11y'), () => { | ||
test('should have the main role', async ({ page }) => { | ||
await page.setContent( | ||
` | ||
<ion-content></ion-content> | ||
`, | ||
config | ||
); | ||
const content = page.locator('ion-content'); | ||
|
||
await expect(content).toHaveAttribute('role', 'main'); | ||
}); | ||
|
||
test('should have no role in popover', async ({ page }) => { | ||
await page.setContent( | ||
` | ||
<ion-popover> | ||
<ion-content></ion-content> | ||
</ion-popover> | ||
`, | ||
config | ||
); | ||
|
||
const content = page.locator('ion-content'); | ||
|
||
/** | ||
* Playwright can't do .not.toHaveAttribute() because a value is expected, | ||
* and toHaveAttribute can't accept a value of type null. | ||
*/ | ||
const role = await content.getAttribute('role'); | ||
expect(role).toBeNull(); | ||
}); | ||
|
||
test('should allow for custom role', async ({ page }) => { | ||
await page.setContent( | ||
` | ||
<ion-content role="complementary"></ion-content> | ||
`, | ||
config | ||
); | ||
const content = page.locator('ion-content'); | ||
|
||
await expect(content).toHaveAttribute('role', 'complementary'); | ||
}); | ||
|
||
test('should allow for custom role in popover', async ({ page }) => { | ||
await page.setContent( | ||
` | ||
<ion-popover> | ||
<ion-content role="complementary"></ion-content> | ||
</ion-popover> | ||
`, | ||
config | ||
); | ||
const content = page.locator('ion-content'); | ||
|
||
await expect(content).toHaveAttribute('role', 'complementary'); | ||
}); | ||
}); | ||
}); |
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,33 @@ | ||
import { expect } from '@playwright/test'; | ||
import { configs, test } from '@utils/test/playwright'; | ||
|
||
/** | ||
* Footer does not have mode-specific styling | ||
*/ | ||
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => { | ||
test.describe(title('footer: a11y'), () => { | ||
test('should have the contentinfo role', async ({ page }) => { | ||
await page.setContent( | ||
` | ||
<ion-footer></ion-footer> | ||
`, | ||
config | ||
); | ||
const footer = page.locator('ion-footer'); | ||
|
||
await expect(footer).toHaveAttribute('role', 'contentinfo'); | ||
}); | ||
|
||
test('should allow for custom role', async ({ page }) => { | ||
await page.setContent( | ||
` | ||
<ion-footer role="complementary"></ion-footer> | ||
`, | ||
config | ||
); | ||
const footer = page.locator('ion-footer'); | ||
|
||
await expect(footer).toHaveAttribute('role', 'complementary'); | ||
}); | ||
}); | ||
}); |
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