From 90504d9b6cd1b29b19a2bbd5010e35c37f0cc591 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Sat, 3 Oct 2020 19:47:39 +0100 Subject: [PATCH] Don't prefix with the page title on focus Doing this was helpful to Voiceover users as its announcement of the label meant the page title (normally announced onload) wasn't skipped. This isn't the case with JAWS so, prefixing the title makes it announce it twice. JAWS has a lot more users and the title being announced twice is more confusing than not at all so this removes it. --- app/assets/javascripts/autofocus.js | 14 +------------- tests/javascripts/autofocus.test.js | 22 ---------------------- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/app/assets/javascripts/autofocus.js b/app/assets/javascripts/autofocus.js index 4d3d94849..97267b32e 100644 --- a/app/assets/javascripts/autofocus.js +++ b/app/assets/javascripts/autofocus.js @@ -4,26 +4,14 @@ Modules.Autofocus = function() { this.start = function(component) { var $component = $(component), - forceFocus = $component.data('forceFocus'), - labelText = $('label[for="' + $component.attr('id') + '"]').eq(0).text().trim(), - clearAriaLabel = evt => { - $component.removeAttr('aria-label'); - $component.off('blur', clearAriaLabel); - }; + 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; } - // screenreaders announce the page title when a new page loads - // this will be lost when focus is moved to our form control so add it to the label instead - $component.attr('aria-label', document.title + ' - ' + labelText); - $component.filter('input, textarea, select').eq(0).trigger('focus'); - // the page title prefix is only needed on page load so remove once focus has shifted - $component.on('blur', clearAriaLabel); - }; }; diff --git a/tests/javascripts/autofocus.test.js b/tests/javascripts/autofocus.test.js index 5ea5179a8..04b207ca5 100644 --- a/tests/javascripts/autofocus.test.js +++ b/tests/javascripts/autofocus.test.js @@ -50,28 +50,6 @@ describe('Autofocus', () => { }); - test('has a label including the page title when the module starts', () => { - - // start module - window.GOVUK.modules.start(); - - expect(search.hasAttribute('aria-label')).toBe(true); - expect(search.getAttribute('aria-label')).toEqual(document.title + ' - ' + labelText); - - }); - - test('gets the original label back when focus moves away', () => { - - // start module - window.GOVUK.modules.start(); - - // shift focus away from textbox - helpers.triggerEvent(search, 'blur'); - - expect(search.hasAttribute('aria-label')).toBe(false); - - }); - test('is not focused if the window has scrolled', () => { // mock the window being scrolled 25px