From ae5755d96fe7f1b4234fb5f48220509664113590 Mon Sep 17 00:00:00 2001 From: Joen A <1204802+jasmussen@users.noreply.github.com> Date: Thu, 27 May 2021 17:25:07 +0200 Subject: [PATCH] Lock the document from scrolling when the modal is open. (#32269) * Lock the document from scrolling when the modal is open. * Update packages/block-library/src/navigation/frontend.js Co-authored-by: Vicente Canales <1157901+vcanales@users.noreply.github.com> Co-authored-by: Vicente Canales <1157901+vcanales@users.noreply.github.com> --- packages/block-library/src/navigation/frontend.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/block-library/src/navigation/frontend.js b/packages/block-library/src/navigation/frontend.js index 592106763e482..1bf1f9fa3a51f 100644 --- a/packages/block-library/src/navigation/frontend.js +++ b/packages/block-library/src/navigation/frontend.js @@ -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' ); + htmlElement.classList.toggle( 'has-modal-open' ); } MicroModal.init( {