Created
April 30, 2024 18:25
-
-
Save SteveJonesDev/a8b38560b4643765f38f126480bc6b7a to your computer and use it in GitHub Desktop.
Elementor Slides Widget - Hide duplicate slides available to keyboard users in the Dom for better accessibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', function() { | |
const swiperWrapper = document.querySelector('.swiper-wrapper'); | |
if (!swiperWrapper) { | |
console.error('Swiper wrapper not found!'); | |
return; | |
} | |
const observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if (mutation.type === 'childList') { | |
mutation.addedNodes.forEach(function(node) { | |
if (node.classList && node.classList.contains('swiper-slide-duplicate')) { | |
node.setAttribute('aria-hidden', 'true'); | |
// Set tabindex="-1" on all focusable elements within the node | |
const focusableElements = node.querySelectorAll('a, button, input, textarea, select, [tabindex]'); | |
focusableElements.forEach(function(element) { | |
element.setAttribute('tabindex', '-1'); | |
}); | |
} | |
}); | |
} | |
}); | |
}); | |
// Configuration of the observer: | |
const config = { childList: true, subtree: true }; | |
// Start observing the target node for configured mutations | |
observer.observe(swiperWrapper, config); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment