mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-07 05:12:31 +02:00
fix(v2): reinit hideable header position when page switched (#2160)
* fix(v2): reinit hideable header position when page switched * fix(v2): fix CI * refactor(v2): use react-router-dom hook instead plugin API
This commit is contained in:
parent
c494e93564
commit
de57ab1b7d
3 changed files with 161 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import {useState, useCallback, useEffect} from 'react';
|
||||
import {useLocation} from 'react-router-dom';
|
||||
|
||||
const useHideableNavbar = hideOnScroll => {
|
||||
const [isNavbarVisible, setIsNavbarVisible] = useState(true);
|
||||
|
@ -16,6 +17,7 @@ const useHideableNavbar = hideOnScroll => {
|
|||
setNavbarHeight(node.getBoundingClientRect().height);
|
||||
}
|
||||
}, []);
|
||||
const location = useLocation();
|
||||
|
||||
const handleScroll = () => {
|
||||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||||
|
@ -47,6 +49,10 @@ const useHideableNavbar = hideOnScroll => {
|
|||
};
|
||||
}, [lastScrollTop, navbarHeight]);
|
||||
|
||||
useEffect(() => {
|
||||
setIsNavbarVisible(true);
|
||||
}, [location]);
|
||||
|
||||
return {
|
||||
navbarRef,
|
||||
isNavbarVisible,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue