mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-16 18:13:54 -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
|
// is still where users intend to start
|
||||||
if (($(window).scrollTop() > 0) && !forceFocus) { return; }
|
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
|
// set up DOM
|
||||||
document.body.innerHTML =
|
document.body.innerHTML =
|
||||||
`<div data-module="autofocus">
|
`<div>
|
||||||
<label class="form-label" for="search">
|
<label class="form-label" for="search">
|
||||||
Search by name
|
Search by name
|
||||||
</label>
|
</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>`;
|
</div>`;
|
||||||
|
|
||||||
focusHandler = jest.fn();
|
focusHandler = jest.fn();
|
||||||
@@ -63,7 +63,7 @@ describe('Autofocus', () => {
|
|||||||
$.prototype.scrollTop = jest.fn(() => 25);
|
$.prototype.scrollTop = jest.fn(() => 25);
|
||||||
|
|
||||||
// set the force-focus flag
|
// set the force-focus flag
|
||||||
document.querySelector('div').setAttribute('data-force-focus', true);
|
document.querySelector('#search').setAttribute('data-force-focus', true);
|
||||||
|
|
||||||
// start module
|
// start module
|
||||||
window.GOVUK.modules.start();
|
window.GOVUK.modules.start();
|
||||||
|
|||||||
Reference in New Issue
Block a user