Skip to content

Commit

Permalink
add setupSkipToFirstResult function to search js that enables keyboar…
Browse files Browse the repository at this point in the history
…d nav filter skipping functionality
  • Loading branch information
PhilipDeFraties committed Aug 22, 2024
1 parent 17117ad commit c836d94
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/views/practices/_search.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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');;
Expand All @@ -1102,6 +1121,7 @@ function execSearchFunctions() {
addAllCheckBoxListener('.all-communities-checkbox', '.communities-checkbox');
searchPracticesPage(skipSearchTracking);
moveFilters();
setupSkipToFirstResult();
}

window.addEventListener('resize', moveFilters);
Expand Down

0 comments on commit c836d94

Please sign in to comment.