feat(SW-1111) Added Suspense on map
This commit is contained in:
@@ -21,6 +21,38 @@ export function MapContainer({ children }: { children: React.ReactNode }) {
|
||||
setMapTop(`${topPosition + scrollY}px`)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const originalOverflowY = document.body.style.overflowY
|
||||
|
||||
// Function to enforce overflowY to hidden
|
||||
const enforceOverflowHidden = () => {
|
||||
if (document.body.style.overflowY !== "hidden") {
|
||||
document.body.style.overflowY = "hidden"
|
||||
}
|
||||
}
|
||||
|
||||
// Set overflowY to hidden initially
|
||||
enforceOverflowHidden()
|
||||
|
||||
// Create a MutationObserver to watch for changes to the style attribute
|
||||
const observer = new MutationObserver(() => {
|
||||
enforceOverflowHidden()
|
||||
})
|
||||
|
||||
// Observe changes to the style attribute of the body
|
||||
observer.observe(document.body, {
|
||||
attributes: true,
|
||||
attributeFilter: ["style"],
|
||||
})
|
||||
|
||||
return () => {
|
||||
// Disconnect the observer on cleanup
|
||||
observer.disconnect()
|
||||
// Restore the original overflowY style
|
||||
document.body.style.overflowY = originalOverflowY
|
||||
}
|
||||
}, [])
|
||||
|
||||
// Making sure the map is always opened at the top of the page,
|
||||
// just below the header and booking widget as these should stay visible.
|
||||
// When closing, the page should scroll back to the position it was before opening the map.
|
||||
|
||||
Reference in New Issue
Block a user