feat(SW-343): Handle escape route without useHandleKeyUp

This commit is contained in:
Pontus Dreij
2024-11-06 09:42:19 +01:00
parent d83126d133
commit 9593348d35

View File

@@ -4,7 +4,6 @@ import { useRouter } from "next/navigation"
import { useCallback, useEffect, useRef, useState } from "react" import { useCallback, useEffect, useRef, useState } from "react"
import { Dialog, Modal } from "react-aria-components" import { Dialog, Modal } from "react-aria-components"
import { useHandleKeyUp } from "@/hooks/useHandleKeyUp"
import { debounce } from "@/utils/debounce" import { debounce } from "@/utils/debounce"
import styles from "./mapModal.module.css" import styles from "./mapModal.module.css"
@@ -13,20 +12,18 @@ export function MapModal({ children }: { children: React.ReactNode }) {
const router = useRouter() const router = useRouter()
const [mapHeight, setMapHeight] = useState("0px") const [mapHeight, setMapHeight] = useState("0px")
const [mapTop, setMapTop] = useState("0px") const [mapTop, setMapTop] = useState("0px")
const [isOpen, setOpen] = useState(true)
const [scrollHeightWhenOpened, setScrollHeightWhenOpened] = useState(0) const [scrollHeightWhenOpened, setScrollHeightWhenOpened] = useState(0)
const rootDiv = useRef<HTMLDivElement | null>(null) const rootDiv = useRef<HTMLDivElement | null>(null)
function onDismiss() { const handleOnOpenChange = (open: boolean) => {
router.back() setOpen(open)
} if (!open) {
router.back()
useHandleKeyUp((event: KeyboardEvent) => {
if (event.key === "Escape") {
onDismiss()
} }
}) }
// Calculate the height of the map based on the viewport height from the start-point (below the header and booking widget) // Calculate the height of the map based on the viewport height from the start-point (below the header and booking widget)
const handleMapHeight = useCallback(() => { const handleMapHeight = useCallback(() => {
@@ -70,7 +67,7 @@ export function MapModal({ children }: { children: React.ReactNode }) {
return ( return (
<div className={styles.wrapper} ref={rootDiv}> <div className={styles.wrapper} ref={rootDiv}>
<Modal isOpen={true}> <Modal isDismissable isOpen={isOpen} onOpenChange={handleOnOpenChange}>
<Dialog <Dialog
style={ style={
{ {