Merged in fix/SW-960-tap-outside-card-map-mobile (pull request #958)
fix(SW-960) close hotel card in map on click outside (mobile) Approved-by: Niclas Edenvin
This commit is contained in:
@@ -60,7 +60,7 @@ export default function HotelCardDialogListing({
|
|||||||
const elements = document.querySelectorAll("[data-name]")
|
const elements = document.querySelectorAll("[data-name]")
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
elements.forEach((el) => observerRef.current?.observe(el))
|
elements.forEach((el) => observerRef.current?.observe(el))
|
||||||
}, 500)
|
}, 1000)
|
||||||
}
|
}
|
||||||
}, [activeCard])
|
}, [activeCard])
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ import {
|
|||||||
AdvancedMarker,
|
AdvancedMarker,
|
||||||
AdvancedMarkerAnchorPoint,
|
AdvancedMarkerAnchorPoint,
|
||||||
} from "@vis.gl/react-google-maps"
|
} from "@vis.gl/react-google-maps"
|
||||||
import { useState } from "react"
|
import { useRef, useState } from "react"
|
||||||
|
|
||||||
import HotelCardDialog from "@/components/HotelReservation/HotelCardDialog"
|
import HotelCardDialog from "@/components/HotelReservation/HotelCardDialog"
|
||||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||||
|
import useClickOutside from "@/hooks/useClickOutside"
|
||||||
|
|
||||||
import HotelMarker from "../../Markers/HotelMarker"
|
import HotelMarker from "../../Markers/HotelMarker"
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ export default function HotelListingMapContent({
|
|||||||
onActiveHotelPinChange,
|
onActiveHotelPinChange,
|
||||||
}: HotelListingMapContentProps) {
|
}: HotelListingMapContentProps) {
|
||||||
const [hoveredHotelPin, setHoveredHotelPin] = useState<string | null>(null)
|
const [hoveredHotelPin, setHoveredHotelPin] = useState<string | null>(null)
|
||||||
|
const dialogRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
function toggleActiveHotelPin(pinName: string | null) {
|
function toggleActiveHotelPin(pinName: string | null) {
|
||||||
if (onActiveHotelPinChange) {
|
if (onActiveHotelPinChange) {
|
||||||
@@ -31,6 +33,10 @@ export default function HotelListingMapContent({
|
|||||||
return activeHotelPin === pinName || hoveredHotelPin === pinName
|
return activeHotelPin === pinName || hoveredHotelPin === pinName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useClickOutside(dialogRef, isPinActiveOrHovered(activeHotelPin ?? ""), () => {
|
||||||
|
toggleActiveHotelPin(null)
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{hotelPins.map((pin) => {
|
{hotelPins.map((pin) => {
|
||||||
@@ -44,13 +50,13 @@ export default function HotelListingMapContent({
|
|||||||
zIndex={isActiveOrHovered ? 2 : 0}
|
zIndex={isActiveOrHovered ? 2 : 0}
|
||||||
onMouseEnter={() => setHoveredHotelPin(pin.name)}
|
onMouseEnter={() => setHoveredHotelPin(pin.name)}
|
||||||
onMouseLeave={() => setHoveredHotelPin(null)}
|
onMouseLeave={() => setHoveredHotelPin(null)}
|
||||||
onClick={() =>
|
onClick={() => {
|
||||||
toggleActiveHotelPin(
|
toggleActiveHotelPin(
|
||||||
activeHotelPin === pin.name ? null : pin.name
|
activeHotelPin === pin.name ? null : pin.name
|
||||||
)
|
)
|
||||||
}
|
}}
|
||||||
>
|
>
|
||||||
<div className={styles.dialogContainer}>
|
<div className={styles.dialogContainer} ref={dialogRef}>
|
||||||
<HotelCardDialog
|
<HotelCardDialog
|
||||||
isOpen={isActiveOrHovered}
|
isOpen={isActiveOrHovered}
|
||||||
handleClose={(event: { stopPropagation: () => void }) => {
|
handleClose={(event: { stopPropagation: () => void }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user