Skip to content

Commit

Permalink
feat: add new prop InfoWindow.shouldFocus (#254)
Browse files Browse the repository at this point in the history
fixes #253
---------

Co-authored-by: Martin Schuhfuss <m.schuhfuss@gmail.com>
  • Loading branch information
Freundschaft and usefulthink committed Mar 12, 2024
1 parent 089ae0a commit c83ea37
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/info-window.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<InfoWindowProps>) => {
const {children, anchor, onCloseClick, ...infoWindowOptions} = props;
const {children, anchor, shouldFocus, onCloseClick, ...infoWindowOptions} =
props;
const map = useContext(GoogleMapsContext)?.map;

const infoWindowRef = useRef<google.maps.InfoWindow | null>(null);
Expand Down Expand Up @@ -96,8 +98,12 @@ export const InfoWindow = (props: PropsWithChildren<InfoWindowProps>) => {
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)}</>
Expand Down

0 comments on commit c83ea37

Please sign in to comment.