summaryrefslogtreecommitdiff
path: root/web/source/frontend
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-04-09 14:14:20 +0200
committerLibravatar GitHub <noreply@github.com>2025-04-09 14:14:20 +0200
commit19cfa8d126a2ff54298150529e58e5e4f5495f09 (patch)
tree3a569e6c456cc7ea13f16f04c5cd81301b71e5f2 /web/source/frontend
parent[feature] add TOTP two-factor authentication (2FA) (#3960) (diff)
downloadgotosocial-19cfa8d126a2ff54298150529e58e5e4f5495f09.tar.xz
[bugfix] Fix a couple accessibility issues with `:focus` elements (#3979)
* [bugfix/frontend] Fix accessibility/focus issues in settings + web ui * fix little error * tweaks
Diffstat (limited to 'web/source/frontend')
-rw-r--r--web/source/frontend/index.js75
1 files changed, 62 insertions, 13 deletions
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();
}