Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2): reinit hideable header position when page switched #2160

Merged
merged 3 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions packages/docusaurus-theme-classic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"infima": "0.2.0-alpha.3",
"parse-numeric-range": "^0.0.2",
"prism-react-renderer": "^1.0.2",
"react-router-dom": "^5.1.2",
"react-toggle": "^4.1.1"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import {useState, useCallback, useEffect} from 'react';
import {useLocation} from 'react-router-dom';

const useHideableNavbar = hideOnScroll => {
const [isNavbarVisible, setIsNavbarVisible] = useState(true);
Expand All @@ -16,6 +17,7 @@ const useHideableNavbar = hideOnScroll => {
setNavbarHeight(node.getBoundingClientRect().height);
}
}, []);
const location = useLocation();

const handleScroll = () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
Expand Down Expand Up @@ -47,6 +49,10 @@ const useHideableNavbar = hideOnScroll => {
};
}, [lastScrollTop, navbarHeight]);

useEffect(() => {
setIsNavbarVisible(true);
}, [location]);

return {
navbarRef,
isNavbarVisible,
Expand Down