Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] onMouseEnter on AdvancedMarker only works when onClick is set #542

Open
antonio-pbilby opened this issue Sep 20, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@antonio-pbilby
Copy link

Description

Using the onMouseEnter with a AdvancedMarker is only working when the same AdvancedMarker has a onClick property set.
If I'm using the standar Pin, it works just fine.

Steps to Reproduce

<APIProvider
  apiKey={import.meta.env.VITE_API_GOOGLE_MAPS_API_KEY}
  region="BR"
  language="pt-BR"

>
  <Map
    defaultCenter={{
      lat: -15.4,
      lng: -47.4,
    }}
    defaultZoom={10}
    id="plots-list"
    mapId={import.meta.env.VITE_API_GOOGLE_MAPS_MAP_ID}
  >
    {plotLocations.map((plot) => {
      return <AdvancedMarker position={plot.location} key={plot.id} onMouseEnter={() => console.log('test')}
        onClick={() => {}}
      >
        <div>dummy component</div>
      </AdvancedMarker>
    })}
  </Map>
</APIProvider>

Environment

  • Library version: 1.2.0
  • Google maps version: weekly
  • Browser and Version: Chrome 128.0.6613.138 (Official Build) (64-bit)
  • OS: Windows 11

Logs

No response

@antonio-pbilby antonio-pbilby added the bug Something isn't working label Sep 20, 2024
@usefulthink
Copy link
Collaborator

@mrMetalWood can you have a look at that? This sounds like it could have something to do with the gmpClickable option for the advanced markers, which will be set when an onClick callback is defined.

@antonio-pbilby can you check if it works for you when you manually add the clickable prop to your markers?

// set gmpClickable from props (when unspecified, it's true if the onClick event
// callback is specified)
useEffect(() => {
if (!marker) return;
if (clickable !== undefined) marker.gmpClickable = clickable;
else if (onClick) marker.gmpClickable = true;
else marker.gmpClickable = false;
}, [marker, clickable, onClick]);

@antonio-pbilby
Copy link
Author

@mrMetalWood can you have a look at that? This sounds like it could have something to do with the gmpClickable option for the advanced markers, which will be set when an onClick callback is defined.

@antonio-pbilby can you check if it works for you when you manually add the clickable prop to your markers?

// set gmpClickable from props (when unspecified, it's true if the onClick event
// callback is specified)
useEffect(() => {
if (!marker) return;
if (clickable !== undefined) marker.gmpClickable = clickable;
else if (onClick) marker.gmpClickable = true;
else marker.gmpClickable = false;
}, [marker, clickable, onClick]);

It worked with the default Pin, but not with my custom component.

Does not work:

<AdvancedMarker position={plot.location} key={plot.id}
  onMouseEnter={() => setHighlightedPlot(plot.id)}
  onMouseLeave={() => setHighlightedPlot(null)}
  clickable
>
  <div>dummy</div>
</AdvancedMarker>

Works:

<AdvancedMarker position={plot.location} key={plot.id}
  onMouseEnter={() => setHighlightedPlot(plot.id)}
  onMouseLeave={() => setHighlightedPlot(null)}
  clickable
/>

@mrMetalWood
Copy link
Collaborator

The gmpClickable is only available in the beta version of the api. https://developers.google.com/maps/documentation/javascript/reference/advanced-markers#AdvancedMarkerElement.gmpClickable

We could add a pointer-events: all to one of our markers wrappers when any of the interaction props (clickable, onClick, onMouseEnter, onMouseLeave) are set.

@usefulthink
Copy link
Collaborator

Sounds good. Should also apply for the onDrag* events as interaction props.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants