generated from cloud-gov/pages-uswds-11ty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a potentiall js solution for modal issue
- Loading branch information
Showing
3 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(function() { | ||
const modal=document.querySelector('#disclaimer-modal-1'); | ||
let overlay=document.getElementsByClassName("usa-modal-overlay"); | ||
const bodyContent = document.querySelector('.usa-app'); | ||
const nonModals = document.querySelectorAll('body > *:not(.usa-modal-wrapper)'); | ||
const openButton=document.querySelector('[data-open-modal]'); | ||
|
||
// Function to add inert attribute when modal is open | ||
const addInert=() => { | ||
nonModals.forEach(el => { | ||
el.setAttribute('inert','true'); | ||
}); | ||
}; | ||
|
||
// Function to remove inert attribute when modal is closed | ||
const removeInert=() => { | ||
document.querySelectorAll('[inert]').forEach(el => { | ||
el.removeAttribute('inert'); | ||
}); | ||
}; | ||
|
||
//openButton.addEventListener('click',addInert); | ||
|
||
openButton.addEventListener('click',function(event) { | ||
addInert(); | ||
}); | ||
|
||
// Listen for the closing event | ||
modal.addEventListener('click',function(event) { | ||
if(!modal.classList.contains('is-visible')) { | ||
removeInert(); | ||
} | ||
}); | ||
|
||
window.addEventListener('load',(event) => { | ||
overlay[0].addEventListener('click',function(event) { | ||
removeInert(); | ||
}); | ||
|
||
openButton.addEventListener('click',function(event) { | ||
bodyContent.removeAttribute('aria-hidden'); | ||
}); | ||
}); | ||
})(); |