From c83ea375295699ed4e3c3a4a6f097cad1a4aca7d Mon Sep 17 00:00:00 2001 From: Qiong Wu Date: Tue, 12 Mar 2024 08:54:04 +0100 Subject: [PATCH] feat: add new prop InfoWindow.shouldFocus (#254) fixes #253 --------- Co-authored-by: Martin Schuhfuss --- src/components/info-window.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/info-window.tsx b/src/components/info-window.tsx index 68a2b815..e060dfa5 100644 --- a/src/components/info-window.tsx +++ b/src/components/info-window.tsx @@ -16,13 +16,15 @@ import {GoogleMapsContext} from './map'; export type InfoWindowProps = google.maps.InfoWindowOptions & { onCloseClick?: () => void; anchor?: google.maps.Marker | google.maps.marker.AdvancedMarkerElement | null; + shouldFocus?: boolean; }; /** * Component to render a Google Maps Info Window */ export const InfoWindow = (props: PropsWithChildren) => { - const {children, anchor, onCloseClick, ...infoWindowOptions} = props; + const {children, anchor, shouldFocus, onCloseClick, ...infoWindowOptions} = + props; const map = useContext(GoogleMapsContext)?.map; const infoWindowRef = useRef(null); @@ -96,8 +98,12 @@ export const InfoWindow = (props: PropsWithChildren) => { openOptions.anchor = anchor; } + if (shouldFocus) { + openOptions.shouldFocus = shouldFocus; + } + infoWindowRef.current.open(openOptions); - }, [contentContainer, infoWindowRef, anchor, map]); + }, [contentContainer, infoWindowRef, anchor, map, shouldFocus]); return ( <>{contentContainer !== null && createPortal(children, contentContainer)}