-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #671 from alphagov/focus-error-summary-on-window-load
Focus error summary on window load
- Loading branch information
Showing
7 changed files
with
64 additions
and
5 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,17 @@ | ||
import '../globals/polyfills/Event' // addEventListener | ||
|
||
function ErrorSummary ($module) { | ||
this.$module = $module | ||
} | ||
|
||
ErrorSummary.prototype.init = function () { | ||
var $module = this.$module | ||
if (!$module) { | ||
return | ||
} | ||
window.addEventListener('load', function () { | ||
$module.focus() | ||
}) | ||
} | ||
|
||
export default ErrorSummary |
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,31 @@ | ||
/** | ||
* @jest-environment ./lib/puppeteer/environment.js | ||
*/ | ||
/* eslint-env jest */ | ||
|
||
const configPaths = require('../../config/paths.json') | ||
const PORT = configPaths.ports.test | ||
|
||
let browser | ||
let page | ||
let baseUrl = 'http://localhost:' + PORT | ||
|
||
beforeAll(async (done) => { | ||
browser = global.__BROWSER__ | ||
page = await browser.newPage() | ||
done() | ||
}) | ||
|
||
afterAll(async (done) => { | ||
await page.close() | ||
done() | ||
}) | ||
|
||
describe('Error Summary', () => { | ||
it('is automatically focused when the page loads', async () => { | ||
await page.goto(baseUrl + '/components/error-summary/preview', { waitUntil: 'load' }) | ||
|
||
const moduleName = await page.evaluate(() => document.activeElement.dataset.module) | ||
expect(moduleName).toBe('error-summary') | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
accessibilityCriteria: | | ||
- Must be focused when the page loads | ||
examples: | ||
- name: default | ||
data: | ||
|
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