Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent tabTrap while modal is closed
Browse files Browse the repository at this point in the history
jadutter committed Oct 17, 2023
1 parent f4d2177 commit cdcbad7
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/modal/lib/utils.js
Original file line number Diff line number Diff line change
@@ -51,15 +51,16 @@ export function setupTabTrap() {

function trapTabKey(e) {
// Check for TAB key press
if (e.keyCode === 9) {
if (e.keyCode === 9 && !document.querySelector('.modal-closed')) {
const tabArray = arrayFrom(document.querySelectorAll(focusableElementsString)).filter(
node => window.getComputedStyle(node).visibility === 'visible'
);

// SHIFT + TAB
if (e.shiftKey && document.activeElement === tabArray[0]) {
e.preventDefault();
tabArray[tabArray.length - 1].focus();
} else if (!e.shiftKey && document.activeElement === tabArray[tabArray.length - 1]) {
} else if (document.activeElement === tabArray[tabArray.length - 1]) {
e.preventDefault();
tabArray[0].focus();
}
2 changes: 1 addition & 1 deletion src/components/modal/v2/lib/utils.js
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ export function setupTabTrap() {

function trapTabKey(e) {
// Check for TAB key press
if (e.keyCode === 9) {
if (e.keyCode === 9 && !document.querySelector('.modal-closed')) {
const tabArray = arrayFrom(document.querySelectorAll(focusableElementsString)).filter(
node => window.getComputedStyle(node).visibility === 'visible'
);

0 comments on commit cdcbad7

Please sign in to comment.