Skip to content

Commit

Permalink
Merge pull request #939 from simonasdev/tooltip-position
Browse files Browse the repository at this point in the history
Fix tooltip position prop
  • Loading branch information
PaulLeCam committed Jan 8, 2022
2 parents 4503e90 + acdb61c commit 7beb589
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/react-leaflet/src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const Tooltip = createOverlayComponent<LeafletTooltip, TooltipProps>(
props: TooltipProps,
setOpen: SetOpenFunc,
) {
const { onClose, onOpen } = props
const { onClose, onOpen, position } = props

useEffect(
function addTooltip() {
Expand All @@ -46,6 +46,10 @@ export const Tooltip = createOverlayComponent<LeafletTooltip, TooltipProps>(

const onTooltipOpen = (event: TooltipEvent) => {
if (event.tooltip === instance) {
if (position) {
instance.setLatLng(position)
}

instance.update()
setOpen(true)
onOpen?.()
Expand Down Expand Up @@ -76,7 +80,7 @@ export const Tooltip = createOverlayComponent<LeafletTooltip, TooltipProps>(
}
}
},
[element, context, setOpen, onClose, onOpen],
[element, context, setOpen, onClose, onOpen, position],
)
},
)

0 comments on commit 7beb589

Please sign in to comment.