From acdb61ce83a7086b51f1247486a8143765868dc3 Mon Sep 17 00:00:00 2001 From: Simonas Gildutis Date: Wed, 5 Jan 2022 15:01:40 +0200 Subject: [PATCH] set tooltip latlng to position prop on open --- packages/react-leaflet/src/Tooltip.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react-leaflet/src/Tooltip.tsx b/packages/react-leaflet/src/Tooltip.tsx index b26e3e9b..09d98d57 100644 --- a/packages/react-leaflet/src/Tooltip.tsx +++ b/packages/react-leaflet/src/Tooltip.tsx @@ -33,7 +33,7 @@ export const Tooltip = createOverlayComponent( props: TooltipProps, setOpen: SetOpenFunc, ) { - const { onClose, onOpen } = props + const { onClose, onOpen, position } = props useEffect( function addTooltip() { @@ -46,6 +46,10 @@ export const Tooltip = createOverlayComponent( const onTooltipOpen = (event: TooltipEvent) => { if (event.tooltip === instance) { + if (position) { + instance.setLatLng(position) + } + instance.update() setOpen(true) onOpen?.() @@ -76,7 +80,7 @@ export const Tooltip = createOverlayComponent( } } }, - [element, context, setOpen, onClose, onOpen], + [element, context, setOpen, onClose, onOpen, position], ) }, )