From 3005a4662ce8df9eb0e3bf5d6b4124ba64b45777 Mon Sep 17 00:00:00 2001 From: Alexis BENOIT Date: Thu, 28 Nov 2024 16:06:52 +0100 Subject: [PATCH] [a11y] Modification des tags de la recherche (#791) --- assets/js/theme/design-system/search.js | 27 ++++++++++++++++++++++++- layouts/partials/header/search.html | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/assets/js/theme/design-system/search.js b/assets/js/theme/design-system/search.js index fd00c419c..08c99edd6 100644 --- a/assets/js/theme/design-system/search.js +++ b/assets/js/theme/design-system/search.js @@ -48,10 +48,35 @@ class Search { this.accessibleMessage = document.createElement('p'); this.accessibleMessageContainer.appendChild(this.accessibleMessage); } - setTimeout(this.updateAccessibilityMessageRole.bind(this), speakDelay); + clearTimeout(this.a11yTimeout); + this.a11yTimeout = setTimeout(this.updateAccessibility.bind(this), speakDelay); }); } + updateAccessibility () { + this.updateAccessibilityMessageRole(); + this.updateAccessibilityTags(); + } + + updateAccessibilityTags () { + const results = this.element.querySelectorAll('.pagefind-ui__result'); + + results.forEach(this.updateAccessibilityResult); + } + + updateAccessibilityResult (result) { + let image = result.querySelector('img'), + title = result.querySelector('.pagefind-ui__result-title'); + + if (image) { + image.setAttribute('alt', ''); + } + if (title) { + title.setAttribute('role', 'heading'); + title.setAttribute('aria-level', '2'); + } + } + updateAccessibilityMessageRole () { const message = this.element.querySelector('.pagefind-ui__message'); if (!message) { diff --git a/layouts/partials/header/search.html b/layouts/partials/header/search.html index 2218cecdf..0bfa966a1 100644 --- a/layouts/partials/header/search.html +++ b/layouts/partials/header/search.html @@ -11,4 +11,5 @@ +

{{ i18n "commons.search.title" }}

\ No newline at end of file