Skip to content

Commit 803e1b1

Browse files
authored
Merge pull request JustFly1984#879 from joshcoales/infowindow-children-of-marker
Anchoring InfoWindow children of Markers
2 parents c740dfb + 6fddef0 commit 803e1b1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/react-google-maps-api/src/components/drawing/Marker.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import * as React from 'react'
33
import { unregisterEvents, applyUpdatersToPropsAndRegisterEvents } from '../../utils/helper'
44

55
import MapContext from '../../map-context'
6+
import { HasMarkerAnchor } from '../../types'
67

78
import { Clusterer } from '@react-google-maps/marker-clusterer'
9+
import { ReactNode } from 'react'
810

911
const eventMap = {
1012
onAnimationChanged: 'animation_changed',
@@ -248,7 +250,18 @@ export class Marker extends React.PureComponent<MarkerProps, MarkerState> {
248250
}
249251

250252
render(): React.ReactNode {
251-
return this.props.children || null
253+
let children: ReactNode | null = null
254+
if(this.props.children) {
255+
children = React.Children.map(this.props.children, child => {
256+
if(!React.isValidElement<HasMarkerAnchor>(child)) {
257+
return child;
258+
}
259+
260+
let elementChild: React.ReactElement<HasMarkerAnchor> = child;
261+
return React.cloneElement(elementChild, {anchor: this.state.marker});
262+
})
263+
}
264+
return children || null
252265
}
253266
}
254267

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface HasMarkerAnchor {
2+
anchor?: google.maps.Marker | null
3+
}

0 commit comments

Comments
 (0)