Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export const Sidebar: FC<{
const sidebarRef = useRef<HTMLDivElement | null>(null)
let sidebarItemClicked = false

const handleSidebarItemClick = () => {
const handleSidebarItemClick = (hash: string) => {
setHash(location.hash)
sidebarItemClicked = true
}

useEffect(() => {
setHash(location.hash)
const onHashChange = () => {
setHash(location.hash)

// Don't change scroll position when the hashchange is triggered click, that's bad user experience
if (location.hash && !sidebarItemClicked) {
const el: HTMLAnchorElement | null = document.querySelector(
Expand Down Expand Up @@ -75,7 +75,7 @@ export const Sidebar: FC<{
`block px-5 py-1 menu_item` +
(item.slug === hash.slice(1) ? ' menu_item__active' : '')
}
onClick={handleSidebarItemClick}
onClick={handleSidebarItemClick.bind(null, `#${item.slug}`)}
data-slug={item.slug}
key={index}
data-depth={item.depth}
Expand Down