From c836d94e8c13d75a536b401e561d77bc67db6db8 Mon Sep 17 00:00:00 2001 From: PhilipDeFraties Date: Wed, 21 Aug 2024 18:08:45 -0600 Subject: [PATCH] add setupSkipToFirstResult function to search js that enables keyboard nav filter skipping functionality --- app/views/practices/_search.js.erb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/views/practices/_search.js.erb b/app/views/practices/_search.js.erb index 988cba455..c6830dd15 100644 --- a/app/views/practices/_search.js.erb +++ b/app/views/practices/_search.js.erb @@ -1092,6 +1092,25 @@ function moveFilters() { filtersContainer.style.display = 'block'; } +function setupSkipToFirstResult() { + const skipDiv = document.getElementById('skip-tag-filters'); + + if (skipDiv) { + skipDiv.addEventListener('focus', function() { + document.addEventListener('keydown', function(event) { + if (event.key === 'Enter' || event.key === ' ') { + event.preventDefault(); + + const firstResultLink = document.querySelector('.dm-link-title'); + if (firstResultLink) { + firstResultLink.focus(); + } + } + }, { once: true }); + }); + } +}; + function execSearchFunctions() { const urlParams = new URLSearchParams(window.location.search); const skipSearchTracking = urlParams.has('all_communities') || urlParams.has('category');; @@ -1102,6 +1121,7 @@ function execSearchFunctions() { addAllCheckBoxListener('.all-communities-checkbox', '.communities-checkbox'); searchPracticesPage(skipSearchTracking); moveFilters(); + setupSkipToFirstResult(); } window.addEventListener('resize', moveFilters);