Skip to content

Commit

Permalink
DBC22-2684: Tweaks to focuses hidden by modal
Browse files Browse the repository at this point in the history
  • Loading branch information
minORC authored and ray-oxd committed Sep 4, 2024
1 parent 23c9e88 commit 666113b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/frontend/src/Components/shared/header/UserNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ export default function UserNavigation(props) {
// Hide screen reader content behind the lightbox
const allFocuses = document.querySelectorAll("a, button, input");
allFocuses.forEach((element) => {
element.classList.add("hidden-by-modal");

if (element.hasAttribute("tabindex") ) {

if (element.getAttribute("tabindex") === "0") {
element.classList.add("restore-tabindex");
}

if (element.getAttribute("tabindex") === "-1") {
element.classList.add("already-hidden");
}
}

element.setAttribute("aria-hidden", "true");
element.setAttribute("tabindex", "-1");
});
Expand Down
21 changes: 18 additions & 3 deletions src/frontend/src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,25 @@ export default function Modal() {

const resetAuthModal = () => {
// Reset focus and screen reader content
const allFocuses = document.querySelectorAll("a, button, input");
allFocuses.forEach((element) => {
const allHidden = document.querySelectorAll(".hidden-by-modal");
allHidden.forEach((element) => {
element.removeAttribute("aria-hidden");
element.removeAttribute("tabindex");

if (element.classList.contains("already-hidden")) {
element.classList.remove("already-hidden");
}

else if (element.classList.contains("restore-tabindex")) {
element.setAttribute("tabindex", "0");
element.classList.remove("restore-tabindex");
}

else {
element.removeAttribute("tabindex");
}

element.removeAttribute("aria-hidden");
element.classList.remove("hidden-by-modal");
});

setAuthContext((prior) => {
Expand Down

0 comments on commit 666113b

Please sign in to comment.