diff --git a/app/assets/javascripts/autofocus.js b/app/assets/javascripts/autofocus.js deleted file mode 100644 index b688a9f20..000000000 --- a/app/assets/javascripts/autofocus.js +++ /dev/null @@ -1,27 +0,0 @@ -(function(Modules) { - "use strict"; - - Modules.Autofocus = function() { - this.start = function(component) { - var $component = $(component), - forceFocus = $component.data('forceFocus'); - - // if the page loads with a scroll position, we can't assume the item to focus onload - // is still where users intend to start - if (($(window).scrollTop() > 0) && !forceFocus) { return; } - - // See if the component itself is something we want to send focus to - var target = $component.filter('input, textarea, select'); - - // Otherwise look inside the component to see if there are any elements - // we want to send focus to - if (target.length === 0) { - target = $('input, textarea, select', $component); - } - - target.eq(0).trigger('focus'); - - }; - }; - -})(window.GOVUK.Modules); diff --git a/app/assets/sass/uswds/_legacy-styles.scss b/app/assets/sass/uswds/_legacy-styles.scss index 2198fb037..208270015 100644 --- a/app/assets/sass/uswds/_legacy-styles.scss +++ b/app/assets/sass/uswds/_legacy-styles.scss @@ -375,3 +375,9 @@ h2.recipient-list { } } } + +.usa-search__input, [type=search] { + border-right: 1px solid; + height: 40px; + margin-top: units(1); +} diff --git a/app/templates/components/live-search.html b/app/templates/components/live-search.html index 58683e957..6e3cfd905 100644 --- a/app/templates/components/live-search.html +++ b/app/templates/components/live-search.html @@ -3,7 +3,7 @@ show=False, form=None, label=None, - autofocus=False + autofocus=True ) %} {%- set search_label = label or form.search.label.text %} @@ -13,11 +13,11 @@ } %} {% if autofocus %} - {% set x=param_extensions.__setitem__("attributes", {"data-module": "autofocus"}) %} + {% set _ = param_extensions.__setitem__("attributes", {"autofocus": "autofocus"}) %} {% endif %} {% if show %} - {% if show_search_box %} -
+
{{ live_search(target_selector='.user-list-item', show=True, form=form) }}
{% endif %} -
{% for user in users %} +
{% if user.status != 'cancelled' %}

@@ -101,7 +101,7 @@ {% endif %}

{% endif %} +
{% endfor %} -
{% endblock %} diff --git a/app/templates/views/organizations/organization/users/index.html b/app/templates/views/organizations/organization/users/index.html index f0c667977..86a8d05ed 100644 --- a/app/templates/views/organizations/organization/users/index.html +++ b/app/templates/views/organizations/organization/users/index.html @@ -24,13 +24,13 @@ {% if show_search_box %} -
+
{{ live_search(target_selector='.user-list-item', show=True, form=form) }}
{% endif %} -
{% for user in users %} +
@@ -60,8 +60,8 @@
+
{% endfor %} -
{{ usaButton({ diff --git a/gulpfile.js b/gulpfile.js index 5e8f3ab32..342631628 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -57,7 +57,6 @@ const javascripts = () => { paths.toolkit + 'javascripts/govuk/modules.js', paths.toolkit + 'javascripts/govuk/show-hide-content.js', paths.src + 'javascripts/copyToClipboard.js', - paths.src + 'javascripts/autofocus.js', paths.src + 'javascripts/enhancedTextbox.js', paths.src + 'javascripts/fileUpload.js', paths.src + 'javascripts/radioSelect.js', diff --git a/tests/javascripts/autofocus.test.js b/tests/javascripts/autofocus.test.js deleted file mode 100644 index 3617ca1d9..000000000 --- a/tests/javascripts/autofocus.test.js +++ /dev/null @@ -1,92 +0,0 @@ -const helpers = require('./support/helpers.js'); - -beforeAll(() => { - require('../../app/assets/javascripts/autofocus.js'); -}); - -afterAll(() => { - require('./support/teardown.js'); -}); - -describe('Autofocus', () => { - - const labelText = 'Search by name'; - let focusHandler; - let search; - - beforeEach(() => { - - document.title = 'Find services by name - GOV.UK Notify'; - - // set up DOM - document.body.innerHTML = - `
- - -
`; - - focusHandler = jest.fn(); - search = document.getElementById('search'); - search.addEventListener('focus', focusHandler, false); - - }); - - afterEach(() => { - - document.body.innerHTML = ''; - search.removeEventListener('focus', focusHandler); - focusHandler = null; - - }); - - test('is focused when modules start', () => { - - // start module - window.GOVUK.modules.start(); - - expect(focusHandler).toHaveBeenCalled(); - - }); - - test('is focused when attribute is set on outer element', () => { - - document.getElementById('search').removeAttribute('data-module'); - document.getElementById('wrapper').setAttribute('data-module', 'autofocus'); - - // start module - window.GOVUK.modules.start(); - - expect(focusHandler).toHaveBeenCalled(); - - }); - - test('is not focused if the window has scrolled', () => { - - // mock the window being scrolled 25px - $.prototype.scrollTop = jest.fn(() => 25); - - // start module - window.GOVUK.modules.start(); - - expect(focusHandler).not.toHaveBeenCalled(); - - }); - - test('is focused if the window has scrolled but the force-focus flag is set', () => { - - // mock the window being scrolled 25px - $.prototype.scrollTop = jest.fn(() => 25); - - // set the force-focus flag - document.querySelector('#search').setAttribute('data-force-focus', true); - - // start module - window.GOVUK.modules.start(); - - expect(focusHandler).toHaveBeenCalled(); - - }); - -});