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
19 changes: 9 additions & 10 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,21 @@ export function Navbar({ children }: { children: React.ReactNode }) {
const containerRef = React.useRef<HTMLDivElement>(null)

React.useEffect(() => {
const updateContainerHeight = () => {
if (containerRef.current) {
const height = containerRef.current.offsetHeight
const el = containerRef.current
if (!el) return

const observer = new ResizeObserver((entries) => {
for (const entry of entries) {
const height = entry.borderBoxSize?.[0]?.blockSize ?? el.offsetHeight
document.documentElement.style.setProperty(
'--navbar-height',
`${height}px`,
)
}
}
})

updateContainerHeight() // Initial call to set the height

window.addEventListener('resize', updateContainerHeight)
return () => {
window.removeEventListener('resize', updateContainerHeight)
}
observer.observe(el)
return () => observer.disconnect()
}, [])

const [showMenu, setShowMenu] = React.useState(false)
Expand Down