From b7fab6d54fb3ca4b28d8085773889b107374c14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Thu, 9 Jun 2022 09:58:29 +0200 Subject: [PATCH] Disable page scroll when Mini Cart is open (#6532) --- assets/js/blocks/mini-cart/block.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/assets/js/blocks/mini-cart/block.tsx b/assets/js/blocks/mini-cart/block.tsx index bfc8f3aa408..8fb3025523f 100644 --- a/assets/js/blocks/mini-cart/block.tsx +++ b/assets/js/blocks/mini-cart/block.tsx @@ -78,6 +78,17 @@ const MiniCartBlock = ( { setContentsNode( node ); }, [] ); + useEffect( () => { + const body = document.querySelector( 'body' ); + if ( body ) { + if ( isOpen ) { + Object.assign( body.style, { overflow: 'hidden' } ); + } else { + Object.assign( body.style, { overflow: '' } ); + } + } + }, [ isOpen ] ); + useEffect( () => { if ( contentsNode instanceof Element ) { const container = contentsNode.querySelector(