Fix bug with anchor links after reloading

There was no need for the previous implementation, since the browser handles this nativly. Additional the manual scrolling into view was actually broken, because the heading would disappear behind the menu bar.
This commit is contained in:
Marcus Blättermann 2022-12-13 05:03:23 +01:00
parent 207c9d9e1c
commit d6c9a07faa
No known key found for this signature in database
GPG Key ID: A1E1F04008AC450D

View File

@ -38,7 +38,6 @@ const DropdownNavigation = ({ items, defaultValue }) => {
}
export default function Sidebar({ items = [], pageMenu = [], slug }) {
const [initialized, setInitialized] = useState(false)
const [activeSection, setActiveSection] = useState(null)
const activeRef = useRef()
const activeHeading = getActiveHeading(items, slug)
@ -46,16 +45,10 @@ export default function Sidebar({ items = [], pageMenu = [], slug }) {
useEffect(() => {
const handleInView = ({ detail }) => setActiveSection(detail)
window.addEventListener('inview', handleInView, { passive: true })
if (!initialized) {
if (activeRef && activeRef.current) {
activeRef.current.scrollIntoView({ block: 'center' })
}
setInitialized(true)
}
return () => {
window.removeEventListener('inview', handleInView)
}
}, [initialized])
})
return (
<menu className={classNames('sidebar', classes['root'])}>