Skip to content

Commit

Permalink
fix: safari focus (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadutter authored Oct 17, 2023
1 parent fe91522 commit 827a56d
Show file tree
Hide file tree
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
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/v2/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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'
);
Expand Down

0 comments on commit 827a56d

Please sign in to comment.