From 31e85221675015d15f97942765e0a9d8b814cdf2 Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Mon, 10 Oct 2022 11:39:07 +0330 Subject: [PATCH] fix broken scroll on mobile --- src/theme/Layout/styles.scss | 1 + src/theme/Navbar/index.scss | 7 ++++--- src/theme/Navbar/index.tsx | 19 +++++++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/theme/Layout/styles.scss b/src/theme/Layout/styles.scss index 2c6c56e..3a49db9 100644 --- a/src/theme/Layout/styles.scss +++ b/src/theme/Layout/styles.scss @@ -24,6 +24,7 @@ } :root { + &, body { overflow-x: hidden !important; } diff --git a/src/theme/Navbar/index.scss b/src/theme/Navbar/index.scss index 1575746..cc8ad5b 100644 --- a/src/theme/Navbar/index.scss +++ b/src/theme/Navbar/index.scss @@ -13,11 +13,12 @@ background: none; } -:root { -} - @include utils.responsive('lg', 'down') { .navbar { background: var(--ifm-background-surface-color); } } + +.overflow-hidden { + overflow: hidden !important; +} diff --git a/src/theme/Navbar/index.tsx b/src/theme/Navbar/index.tsx index 05ffc9b..58844fd 100644 --- a/src/theme/Navbar/index.tsx +++ b/src/theme/Navbar/index.tsx @@ -1,12 +1,27 @@ -import React from 'react' +import { useNavbarMobileSidebar } from '@docusaurus/theme-common/internal' +import type { WrapperProps } from '@docusaurus/types' import Navbar from '@theme-original/Navbar' import type NavbarType from '@theme/Navbar' -import type { WrapperProps } from '@docusaurus/types' +import React, { useEffect } from 'react' import './index.scss' type Props = WrapperProps export default function NavbarWrapper(props: Props): JSX.Element { + const mobileSidebar = useNavbarMobileSidebar() + + useEffect(() => { + if (mobileSidebar.shown) { + document + .querySelector('#__docusaurus') + ?.classList?.add?.('overflow-hidden') + } else { + document + .querySelector('#__docusaurus') + ?.classList?.remove?.('overflow-hidden') + } + }, [mobileSidebar.shown]) + return ( <>