Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock the document from scrolling when the modal is open. #32269

Merged
merged 2 commits into from
May 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/block-library/src/navigation/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function navigationToggleModal( modal ) {
triggerButton.setAttribute( 'aria-expanded', ! isHidden );
closeButton.setAttribute( 'aria-expanded', ! isHidden );
modal.classList.toggle( 'has-modal-open', ! isHidden );

// Add a class to indicate the modal is open.
const htmlElement = document.querySelector( 'html' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, can avoid using querySelector here, the same can be achieved through const htmlElement = document.documentElement;.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you! #32303

htmlElement.classList.toggle( 'has-modal-open' );
}

MicroModal.init( {
Expand Down