-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Focus skip link target to fix Mac VoiceOver announcements
When user activates the skip link, Mac VoiceOver currently does not announce the main content or continue reading from it. To improve the experience for Mac VoiceOver users: - make the main content element focusable by adding a `tabindex` attribute - move focus to it programmatically - override the native focus outline to none whilst `tabindex` is present - remove the `tabindex` attribute and the style override on blur This follows the pattern we already use in the error summary and notification banner components. There also seems to be an improvement to the announcements on JAWS (both with Chrome and IE11): JAWS now announces it's on the main region, before it starts reading the main content. Behaviour | Announces skip link when it's navigated to | Announces main has been navigated to | Reads out content of main -- | -- | -- | -- JAWS 2020 / Chrome | same page link skip to main content | enter **main** region **main** region page has 4 regions and 8 headings `<main content>` | enter **main** region **main** region page has 4 regions and 8 headings `<main content>` JAWS 2020 / IE 11 | skip to main content same page link | enter **main** region page has 4 regions and 8 headings `<main content>` | enter main region page has 4 regions and 8 headings `<main content>` NVDA 2021.1/ Firefox 90 | skip to main content link | main landmark `<main content>` | main landmark `<main content>` Voiceover / Safari (macOS Mojave) | skip to main content, link | **main you are currently on a text area** | **`<main content>`** Voiceover / Safari (iOS 15) | Skip to main content, in-page link | After double-tapping to follow link: "Press release, main landmark" | After double-tapping to follow link: "Press release, main landmark" Talkback / Chrome 96 (Android 11) | skip to main content, link | After double-tapping to follow link: "main, Press release, <main content>" | After double-tapping to follow link: "main, Press release, <main content>" (Announcements that have changed from the live version are in **bold** ^) See #2187 (comment) for more details
- Loading branch information
1 parent
3f111f5
commit 0a3d8b3
Showing
4 changed files
with
137 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-env jest */ | ||
|
||
const configPaths = require('../../../../config/paths.json') | ||
const PORT = configPaths.ports.test | ||
|
||
const baseUrl = 'http://localhost:' + PORT | ||
|
||
describe('/examples/template-default', () => { | ||
describe('skip link', () => { | ||
beforeAll(async () => { | ||
await page.goto(`${baseUrl}/examples/template-default`, { waitUntil: 'load' }) | ||
await page.keyboard.press('Tab') | ||
await page.click('.govuk-skip-link') | ||
}) | ||
|
||
it('focuses the target element', async () => { | ||
const activeElement = await page.evaluate(() => document.activeElement.id) | ||
|
||
expect(activeElement).toBe('main-content') | ||
}) | ||
|
||
it('adds the tabindex attribute to the target', async () => { | ||
const tabindex = await page.$eval('.govuk-main-wrapper', el => el.getAttribute('tabindex')) | ||
|
||
expect(tabindex).toBe('-1') | ||
}) | ||
|
||
it('adds the class for removing the native focus style to the target', async () => { | ||
const cssClass = await page.$eval('.govuk-main-wrapper', el => el.getAttribute('class')) | ||
|
||
expect(cssClass).toContain('govuk-skip-link-focused-element') | ||
}) | ||
|
||
it('removes the tabindex attribute from the target on blur', async () => { | ||
await page.$eval('.govuk-main-wrapper', el => el.blur()) | ||
|
||
const tabindex = await page.$eval('.govuk-main-wrapper', el => el.getAttribute('tabindex')) | ||
|
||
expect(tabindex).toBeNull() | ||
}) | ||
|
||
it('removes the class for removing the native focus style from the target on blur', async () => { | ||
await page.$eval('.govuk-main-wrapper', el => el.blur()) | ||
|
||
const cssClass = await page.$eval('.govuk-main-wrapper', el => el.getAttribute('class')) | ||
|
||
expect(cssClass).not.toContain('govuk-skip-link-focused-element') | ||
}) | ||
}) | ||
}) |
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