From c49dc11a796844c7847795eff03db5ea1a09769e Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 7 Aug 2024 11:23:06 -0500 Subject: [PATCH] Remove an obsolete fix for skip to nav links As of 2015 this is no longer a problem. See the amended intro at https://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/ --- app/javascript/application.js | 5 ++--- app/javascript/skip-to-nav.js | 36 ------------------------------- spec/features/skip_to_nav_spec.rb | 14 ------------ 3 files changed, 2 insertions(+), 53 deletions(-) delete mode 100644 app/javascript/skip-to-nav.js diff --git a/app/javascript/application.js b/app/javascript/application.js index 06a4e7d21..66ceab8a4 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -51,12 +51,11 @@ import "./preview-content"; import "./recent-selections"; import "./select-all"; import "./sfx-panel"; -import "./skip-to-nav"; import "./tooltip"; import "./truncate"; import "./update-hidden-inputs-by-checkbox"; -// TODO: Remove this whole method when we upgrade to Blacklight 8, provided that +// TODO: Remove this whole method when we upgrade to Blacklight 8, provided that // https://github.com/projectblacklight/blacklight/pull/3133 is merged // // Add the passed in contents to the modal and display it. @@ -97,4 +96,4 @@ document.addEventListener("turbo:before-cache", function () { }); import "./controllers" -import "./controllers/external" \ No newline at end of file +import "./controllers/external" diff --git a/app/javascript/skip-to-nav.js b/app/javascript/skip-to-nav.js deleted file mode 100644 index fc9339c37..000000000 --- a/app/javascript/skip-to-nav.js +++ /dev/null @@ -1,36 +0,0 @@ -// Inspired from https://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/ - -Blacklight.onLoad(function() { - function setFocusBehaviorForExistingURLHashes() { - var locationHash = location.hash.substring(1); - if (locationHash) { - var clickElement = $('[href="#' + locationHash + '"]'); - var targetElement = $('#' + locationHash); - removeTabIndex(targetElement); - targetElement.focus(); - clickElement.on('click', function() { - targetElement.focus(); - }); - } - } - - function removeTabIndex(element) { - if (element && isTabbableElement(element)) { - element.attr('tabIndex', -1); - } - } - - function isTabbableElement(element) { - return (!/^(?:a|select|input|button|textarea)$/i.test(element.attr('name'))); - } - - setFocusBehaviorForExistingURLHashes(); - - window.addEventListener('hashchange', function(event) { - var element = $('#' + location.hash.substring(1)); - if (element) { - removeTabIndex(element); - element.focus(); - } - }, false); -}); diff --git a/spec/features/skip_to_nav_spec.rb b/spec/features/skip_to_nav_spec.rb index a7d721ecd..ad08cb204 100644 --- a/spec/features/skip_to_nav_spec.rb +++ b/spec/features/skip_to_nav_spec.rb @@ -41,20 +41,6 @@ end end - scenario 'places focus on traditionally non-focusable elements', :js do - visit root_path - - body_element = page.find("body") - body_element.native.send_keys(:tab) - body_element.native.send_keys(:tab) - - within '#skip-link' do - click_link 'Skip to main content' - active_element = page.evaluate_script('$(document.activeElement).attr("id")') - expect(active_element).to eq 'main-container' - end - end - scenario "has skip-to navigation links to search field, main container and records in record view page" do visit solr_document_path 20