fix: Viewport issue in PWA (#995)

* fix: move safe-area padding from body/HTML to navbars. Add script to compute app height dynamically.

* fix: Initialize sankey tooltip with top-0 to avoid overflow

* fix: add fallback to HTML height

* fix: properly set bottom spacing and use position fixed for bottom navbar

* fix: move viewport controller initialization
This commit is contained in:
Alessio Cappa
2026-02-15 13:23:19 +01:00
committed by GitHub
parent e573896efe
commit e0ae71f33a
6 changed files with 56 additions and 9 deletions

View File

@@ -0,0 +1,46 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["content", "bottomNav"]
connect() {
this.updateViewport()
this.updateBottomSpacing()
window.addEventListener("resize", this.handleResize)
window.addEventListener("orientationchange", this.handleResize)
if (this.hasBottomNavTarget) {
this.resizeObserver = new ResizeObserver(() => {
this.updateBottomSpacing()
})
this.resizeObserver.observe(this.bottomNavTarget)
}
}
disconnect() {
window.removeEventListener("resize", this.handleResize)
window.removeEventListener("orientationchange", this.handleResize)
if (this.resizeObserver) {
this.resizeObserver.disconnect()
}
}
handleResize = () => {
this.updateViewport()
this.updateBottomSpacing()
}
updateViewport() {
const height = window.innerHeight
document.documentElement.style.setProperty("--app-height", `${height}px`)
}
updateBottomSpacing() {
if (!this.hasBottomNavTarget || !this.hasContentTarget) return
const navHeight = this.bottomNavTarget.offsetHeight
this.contentTarget.style.paddingBottom = `${navHeight}px`
}
}