Fix the autofocus component

Since moving textboxes to GOV.UK Frontend we’ve started putting the
data attribute on the `input` element itself, not a wrapper around it.

This commit updates the Javascript accordingly.
This commit is contained in:
Chris Hill-Scott
2020-08-27 08:49:36 +01:00
parent db1f916d34
commit 674c27a693
2 changed files with 4 additions and 4 deletions

View File

@@ -9,7 +9,7 @@
// is still where users intend to start
if (($(window).scrollTop() > 0) && !forceFocus) { return; }
$('input, textarea, select', component).eq(0).trigger('focus');
$(component).filter('input, textarea, select').eq(0).trigger('focus');
};
};

View File

@@ -15,11 +15,11 @@ describe('Autofocus', () => {
// set up DOM
document.body.innerHTML =
`<div data-module="autofocus">
`<div>
<label class="form-label" for="search">
Search by name
</label>
<input autocomplete="off" class="form-control form-control-1-1" id="search" name="search" type="search" value="">
<input autocomplete="off" class="form-control form-control-1-1" id="search" name="search" type="search" value="" data-module="autofocus">
</div>`;
focusHandler = jest.fn();
@@ -63,7 +63,7 @@ describe('Autofocus', () => {
$.prototype.scrollTop = jest.fn(() => 25);
// set the force-focus flag
document.querySelector('div').setAttribute('data-force-focus', true);
document.querySelector('#search').setAttribute('data-force-focus', true);
// start module
window.GOVUK.modules.start();