Skip to content

Commit fa16278

Browse files
committed
fix: re-position the buttongroup if the footer is visible (#1340)
1 parent e782462 commit fa16278

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

app/pages/package/[[org]]/[name].vue

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const router = useRouter()
2828
2929
const header = useTemplateRef('header')
3030
const isHeaderPinned = shallowRef(false)
31+
const navExtraOffset = shallowRef(0)
3132
3233
function checkHeaderPosition() {
3334
const el = header.value
@@ -40,13 +41,37 @@ function checkHeaderPosition() {
4041
isHeaderPinned.value = Math.abs(rect.top - top) < 1
4142
}
4243
44+
let footerEl: HTMLElement | null = null
45+
let footerObserver: IntersectionObserver | null = null
46+
4347
useEventListener('scroll', checkHeaderPosition, { passive: true })
4448
useEventListener('resize', checkHeaderPosition)
4549
4650
onMounted(() => {
4751
checkHeaderPosition()
52+
footerEl = document.querySelector('footer')
53+
if (!footerEl) return
54+
const thresholdValues = Array.from({ length: 101 }, (_, index) => index / 100)
55+
footerObserver = new IntersectionObserver(
56+
entries => {
57+
const entry = entries[0]
58+
if (!entry) return
59+
navExtraOffset.value = entry.isIntersecting ? entry.intersectionRect.height : 0
60+
},
61+
{ threshold: thresholdValues },
62+
)
63+
footerObserver.observe(footerEl)
4864
})
4965
66+
onBeforeUnmount(() => {
67+
footerObserver?.disconnect()
68+
footerObserver = null
69+
})
70+
71+
const navExtraOffsetStyle = computed(() => ({
72+
'--package-nav-extra': `${navExtraOffset.value}px`,
73+
}))
74+
5075
const { packageName, requestedVersion, orgName } = usePackageRoute()
5176
const selectedPM = useSelectedPackageManager()
5277
const activePmId = computed(() => selectedPM.value ?? 'npm')
@@ -647,6 +672,7 @@ onKeyStroke(
647672
as="nav"
648673
:aria-label="$t('package.navigation')"
649674
class="hidden sm:flex max-sm:flex max-sm:fixed max-sm:z-40 max-sm:inset-is-1/2 max-sm:-translate-x-1/2 max-sm:rtl:translate-x-1/2 max-sm:bg-[--bg]/90 max-sm:backdrop-blur-md max-sm:border max-sm:border-border max-sm:rounded-md max-sm:shadow-md"
675+
:style="navExtraOffsetStyle"
650676
:class="$style.packageNav"
651677
>
652678
<LinkBase
@@ -1460,7 +1486,7 @@ onKeyStroke(
14601486
/* Mobile floating nav: safe-area positioning + kbd hiding */
14611487
@media (max-width: 639.9px) {
14621488
.packageNav {
1463-
bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
1489+
bottom: calc(1.25rem + var(--package-nav-extra, 0px) + env(safe-area-inset-bottom, 0px));
14641490
}
14651491
14661492
.packageNav > :global(a kbd) {

0 commit comments

Comments
 (0)