From 19cfa8d126a2ff54298150529e58e5e4f5495f09 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:14:20 +0200 Subject: [bugfix] Fix a couple accessibility issues with `:focus` elements (#3979) * [bugfix/frontend] Fix accessibility/focus issues in settings + web ui * fix little error * tweaks --- web/source/frontend/index.js | 75 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 13 deletions(-) (limited to 'web/source/frontend') diff --git a/web/source/frontend/index.js b/web/source/frontend/index.js index 5a6224994..6d4b1470d 100644 --- a/web/source/frontend/index.js +++ b/web/source/frontend/index.js @@ -143,11 +143,23 @@ lightbox.on('uiRegister', function() { el.setAttribute('target', '_blank'); el.setAttribute('rel', 'noopener'); pswp.on('change', () => { - el.href = pswp.currSlide.data.parentStatus - ? pswp.currSlide.data.parentStatus - : pswp.currSlide.data.element.dataset.pswpParentStatus; + switch (true) { + case pswp.currSlide.data.parentStatus !== undefined: + // Link to parent status. + el.href = pswp.currSlide.data.parentStatus; + break; + case pswp.currSlide.data.element !== undefined && + pswp.currSlide.data.element.dataset.pswpParentStatus !== undefined: + // Link to parent status. + el.href = pswp.currSlide.data.element.dataset.pswpParentStatus; + break; + default: + // Link to profile. + const location = window.location; + el.href = "//" + location.host + location.pathname; + } }); - } + } }); }); @@ -163,26 +175,63 @@ function dynamicSpoiler(className, updateFunc) { }); } -dynamicSpoiler("text-spoiler", (spoiler) => { - const button = spoiler.querySelector(".button"); +dynamicSpoiler("text-spoiler", (details) => { + const summary = details.children[0]; + const button = details.querySelector(".button"); + + // Use button inside summary to + // toggle post body visibility. + button.tabIndex = "0"; + button.setAttribute("aria-role", "button"); + button.onclick = () => { + details.click(); + }; + + // Let enter also trigger the button + // (for those using keyboard to navigate). + button.addEventListener("keydown", (e) => { + if (e.key === "Enter") { + summary.click(); + } + }); + // Change button text depending on + // whether spoiler is open or closed rn. return () => { - button.textContent = spoiler.open + button.textContent = details.open ? "Show less" : "Show more"; }; }); -dynamicSpoiler("media-spoiler", (spoiler) => { - const eye = spoiler.querySelector(".eye.button"); - const video = spoiler.querySelector(".plyr-video"); +dynamicSpoiler("media-spoiler", (details) => { + const summary = details.children[0]; + const button = details.querySelector(".eye.button"); + const video = details.querySelector(".plyr-video"); const loopingAuto = !reduceMotion.matches && video != null && video.classList.contains("gifv"); + // Use button *instead of summary* + // to toggle media visibility. + summary.tabIndex = "-1"; + button.tabIndex = "0"; + button.setAttribute("aria-role", "button"); + button.onclick = () => { + details.click(); + }; + + // Let enter also trigger the button + // (for those using keyboard to navigate). + button.addEventListener("keydown", (e) => { + if (e.key === "Enter") { + summary.click(); + } + }); + return () => { - if (spoiler.open) { - eye.setAttribute("aria-label", "Hide media"); + if (details.open) { + button.setAttribute("aria-label", "Hide media"); } else { - eye.setAttribute("aria-label", "Show media"); + button.setAttribute("aria-label", "Show media"); if (video && !loopingAuto) { video.pause(); } -- cgit v1.2.3