From 4837e8f7ee064af64ac11b3ac4f85bb3ae0b403e Mon Sep 17 00:00:00 2001 From: Zack Stickles Date: Tue, 8 Sep 2020 14:20:45 -0700 Subject: [PATCH] fix: update sidebar positioning based on header height --- src/layouts/MainLayout.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/layouts/MainLayout.js b/src/layouts/MainLayout.js index b5ec18484..aadaaf043 100644 --- a/src/layouts/MainLayout.js +++ b/src/layouts/MainLayout.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useLayoutEffect, useRef } from 'react'; import PropTypes from 'prop-types'; import { css } from '@emotion/core'; @@ -36,6 +36,8 @@ const MainLayout = ({ children }) => { const location = useLocation(); const { fileRelativePath } = usePageContext(); + const headerRef = useRef(null); + const [headerHeight, setHeaderHeight] = useState(0); const [cookieConsent, setCookieConsent] = useState(false); const [isMobileNavOpen, setIsMobileNavOpen] = useState(false); const isComponentDoc = fileRelativePath.includes( @@ -54,10 +56,14 @@ const MainLayout = ({ children }) => { setIsMobileNavOpen(false); }, [location.pathname]); + useLayoutEffect(() => { + setHeaderHeight(headerRef?.current?.clientHeight || 0); + }); + return (
{ ) : null} - +
+ +