Skip to content

Commit

Permalink
fix: replace prop gmpDraggable with draggable in AdvancedMarker (#53
Browse files Browse the repository at this point in the history
)

The Maps JavaScript API had to rename the `draggable` property of the `AdvancedMarkerElement` to `gmpDraggable` to avoid a conflict with the existing [`HTMLElement.draggable`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable?retiredLocale=de) attribute.

This isn't needed for react-components and we want to go with the less confusing and intuitive name `draggable` instead.
  • Loading branch information
osmanonurcan authored Nov 5, 2023
1 parent 42d8ef9 commit 1dbf477
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/components/advanced-marker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ type AdvancedMarkerEventProps = {
};

export type AdvancedMarkerProps = PropsWithChildren<
google.maps.marker.AdvancedMarkerElementOptions &
Omit<google.maps.marker.AdvancedMarkerElementOptions, 'gmpDraggable'> &
AdvancedMarkerEventProps & {
/**
* className to add a class to the advanced marker element
* Can only be used with HTML Marker content
*/
className?: string;
draggable?: boolean;
}
>;

Expand All @@ -58,7 +59,7 @@ function useAdvancedMarker(props: AdvancedMarkerProps) {
onDragStart,
onDragEnd,
collisionBehavior,
gmpDraggable,
draggable,
position,
title,
zIndex
Expand Down Expand Up @@ -103,7 +104,7 @@ function useAdvancedMarker(props: AdvancedMarkerProps) {
if (onDragStart) marker.addListener('dragstart', onDragStart);
if (onDragEnd) marker.addListener('dragend', onDragEnd);

if ((onDrag || onDragStart || onDragEnd) && !gmpDraggable) {
if ((onDrag || onDragStart || onDragEnd) && !draggable) {
console.warn(
'You need to set the marker to draggable to listen to drag-events.'
);
Expand All @@ -112,19 +113,19 @@ function useAdvancedMarker(props: AdvancedMarkerProps) {
return () => {
google.maps.event.clearInstanceListeners(m);
};
}, [marker, gmpDraggable, onClick, onDragStart, onDrag, onDragEnd]);
}, [marker, draggable, onClick, onDragStart, onDrag, onDragEnd]);

// update other marker props when changed
useEffect(() => {
if (!marker) return;

if (position !== undefined) marker.position = position;
if (gmpDraggable !== undefined) marker.gmpDraggable = gmpDraggable;
if (draggable !== undefined) marker.gmpDraggable = draggable;
if (collisionBehavior !== undefined)
marker.collisionBehavior = collisionBehavior;
if (zIndex !== undefined) marker.zIndex = zIndex;
if (typeof title === 'string') marker.title = title;
}, [marker, position, gmpDraggable, collisionBehavior, zIndex, title]);
}, [marker, position, draggable, collisionBehavior, zIndex, title]);

return [marker, contentContainer] as const;
}
Expand Down

0 comments on commit 1dbf477

Please sign in to comment.