Skip to content

Commit

Permalink
replaced plain JS with useref for content-height
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahul committed Dec 21, 2023
1 parent bb80efa commit 17a57be
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/naksha-gmaps-draw/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ModalContent,
ModalHeader,
ModalOverlay,
useDisclosure, // Import useDisclosure hook
useDisclosure,
} from "@chakra-ui/react";
import { Data, GoogleMap, LoadScriptNext } from "@react-google-maps/api";
import React, { useEffect, useMemo, useReducer, useRef, useState } from "react";
Expand Down Expand Up @@ -78,19 +78,19 @@ const NakshaGmapsDraw = React.forwardRef(
ref: any
) => {
const mapRef = useRef<any>(null);
const modalContentRef = useRef<any>(null); /
const [features, dispatch] = useReducer(featuresReducer, data);
const [isLoaded, setIsLoaded] = useState<boolean>();
const { isOpen, onOpen, onClose } = useDisclosure(); // Initialize useDisclosure
const [modalHeight, setModalHeight] = useState("auto");

const [modalHeight, setModalHeight] = useState("auto");

const viewPort = useMemo(
() => mapboxToGmapsViewState(defaultViewState),
[defaultViewState]
);

const reloadFeatures = () => {
// Clear Map
// Clear Map
mapRef.current.state.map.data.forEach(function (feature) {
mapRef.current.state.map.data.remove(feature);
});
Expand Down Expand Up @@ -164,9 +164,8 @@ const NakshaGmapsDraw = React.forwardRef(

useEffect(() => {
if (isOpen) {
// Update modal height when it is open
const contentHeight =
document.getElementById("modal-content")?.offsetHeight;
// Update modal height when it is open using useRef
const contentHeight = modalContentRef.current?.offsetHeight;
setModalHeight(contentHeight ? `${contentHeight}px` : "auto");
}
}, [isOpen]);
Expand Down Expand Up @@ -221,6 +220,7 @@ const NakshaGmapsDraw = React.forwardRef(
>
<ModalOverlay />
<ModalContent
ref={modalContentRef} // Set ref for modal content
style={{
maxWidth: "550px",
height: modalHeight, // Set height to "auto" initially
Expand Down

0 comments on commit 17a57be

Please sign in to comment.