mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-15 17:44:03 -05:00
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:
@@ -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');
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user