Skip to content

Commit 0be6522

Browse files
committed
fix: hide feedback button when it overlaps with navbar
1 parent 76a601a commit 0be6522

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/components/DocFeedbackProvider.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,33 @@ function BlockButton({
349349
onShowNote?: () => void
350350
}) {
351351
const [mounted, setMounted] = React.useState(false)
352+
const [scrollY, setScrollY] = React.useState(0)
352353

353354
React.useEffect(() => {
354355
setMounted(true)
355356
}, [])
356357

358+
// Track scroll position to trigger re-renders for navbar overlap check
359+
React.useEffect(() => {
360+
if (!mounted) return
361+
362+
const handleScroll = () => {
363+
setScrollY(window.scrollY)
364+
}
365+
366+
const handleResize = () => {
367+
setScrollY(window.scrollY)
368+
}
369+
370+
window.addEventListener('scroll', handleScroll, { passive: true })
371+
window.addEventListener('resize', handleResize)
372+
373+
return () => {
374+
window.removeEventListener('scroll', handleScroll)
375+
window.removeEventListener('resize', handleResize)
376+
}
377+
}, [mounted])
378+
357379
if (!mounted) return null
358380

359381
// Find the block element
@@ -371,6 +393,28 @@ function BlockButton({
371393
// Only show button if hovered or menu is open
372394
if (!isHovered && !isMenuOpen) return null
373395

396+
// Check if button would overlap with navbar (synchronous check)
397+
// Using scrollY to trigger re-render on scroll
398+
const navbarHeightStr = getComputedStyle(
399+
document.documentElement,
400+
).getPropertyValue('--navbar-height')
401+
const navbarHeight = parseFloat(navbarHeightStr) || 0
402+
403+
const blockRect = block.getBoundingClientRect()
404+
405+
// Button appears at top-right of block, shifted up by its own height
406+
// The button is approximately 24px (6 * 4 = 24 for w-6 h-6)
407+
const buttonHeight = 24
408+
const buttonTop = blockRect.top - buttonHeight
409+
410+
// Hide button if it would appear above or overlapping with navbar
411+
if (navbarHeight > 0 && buttonTop < navbarHeight && !isMenuOpen) {
412+
return null
413+
}
414+
415+
// Suppress unused state warning - scrollY triggers re-renders
416+
void scrollY
417+
374418
// Create portal container for button positioned at top-right of block
375419
let portalContainer = document.querySelector(
376420
`[data-button-portal="${blockId}"]`,

0 commit comments

Comments
 (0)