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

List of result autocomplete google maps API can't be selected in Sheet Component #2192

Closed
tegarmonster opened this issue Dec 25, 2023 · 10 comments
Labels
stale? Is this issue stale? Stale

Comments

@tegarmonster
Copy link

Hi,
I'm using component Sheet, and add google maps component to SheetContent.. the google component is work, but when I want to select the result of autocomplete, the list cannot be selected

this is because CSS on Sheet component?

image

@lucasprins
Copy link

Why are you using sheet for this? Seems like a combobox could be good for this

https://ui.shadcn.com/docs/components/combobox

Anyway, could you make a code sandbox so we can reproduce and see?

@tegarmonster
Copy link
Author

tegarmonster commented Dec 26, 2023

Hi @lucasprins
I mean I'm using Sheet like this:

<Sheet>
  <MapComponent />
</Sheet>

@kaydenthomson
Copy link

kaydenthomson commented Jan 12, 2024

@tegarmonster did you find a work around for this?

I'm having the same problem with the Dialog component.

This is a similar issue: #2155
And here is an issue on Radix #1859

@kaydenthomson
Copy link

Ben's comment fixed the issue for me. I tested both Dialogs and Sheets and made some minor modifications.

I have an AutocompleteInput component where I added:

useEffect(() => {
  setTimeout(() => (document.body.style.pointerEvents = ""), 0)
}, []) 

Then on SheetContent or DialogContent components, I add the the property onInteractOutside.

onInteractOutside={(e) => {
  const hasPacContainer = e.composedPath().some((el: EventTarget) => {
    if ("classList" in el) {
      return Array.from((el as Element).classList).includes("pac-container")
    }
    return false
  })

  if (hasPacContainer) {
    e.preventDefault()
  }
}}

@shadcn shadcn added the stale? Is this issue stale? label Feb 4, 2024
@shadcn
Copy link
Collaborator

shadcn commented Feb 28, 2024

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

@shadcn shadcn closed this as completed Feb 28, 2024
@dertuman
Copy link

For other people that have come here because of the same issue but in the shadcn Drawer (which uses radix under the hood), nothing else worked to me other than using this, so basically thanks so much to the original poster which I believe is Ben radix-ui/primitives#1859 (comment), this just targets the item instead of the container. And no need to use modal={false}.

<DrawerContent
        onInteractOutside={(e) => {
          const hasPacItem = e.composedPath().some((el: EventTarget) => {
            if ('classList' in el) {
              return Array.from((el as Element).classList).includes('pac-item');
            }
            return false;
          });

          // if we click an autocomplete item, prevent the default onInteractOutside action, to close
          if (hasPacItem) {
            e.preventDefault();
          }
        }}
      >

and in the autocomplete component, to allow the click to go through to the autocomplete items (again thanks to the original poster):

// this is needed to allow pointer events to go through, used to fix the google autocomplete input
  useEffect(() => {
    setTimeout(() => (document.body.style.pointerEvents = ''), 0);
  }, []);

@tegarmonster
Copy link
Author

thanks @kaydenthomson and @dertuman !

@ld-gary
Copy link

ld-gary commented Oct 22, 2024

+1 for @kaydenthomson / @dertuman solution. My head was scratched!

@ricardocoronel
Copy link

ricardocoronel commented Jan 24, 2025

Thanks @kaydenthomson / @dertuman your solution works perfect!

In my case I'm using the StandaloneSearchBox component from @react-google-maps/api.
I created a GoogleMapComponent and inside I added
useEffect(() => { setTimeout(() => (document.body.style.pointerEvents = ""), 0); }, []);

And then in mi component I added
<DialogContent onInteractOutside={(e) => { const hasPacContainer = e .composedPath() .some((el: EventTarget) => { if ("classList" in el) { return Array.from((el as Element).classList).includes( "pac-container" ); } return false; }); if (hasPacContainer) { e.preventDefault(); } }} >

And now it's working perfect! I waste a lot of time looking for fix it before I red your messages.

@dertuman
Copy link

Thanks @kaydenthomson / @dertuman your solution works perfect!

In my case I'm using the component from @react-google-maps/api.
I created a GoogleMapComponent and inside I added
useEffect(() => { setTimeout(() => (document.body.style.pointerEvents = ""), 0); }, []);

And then in mi component I added
<DialogContent onInteractOutside={(e) => { const hasPacContainer = e .composedPath() .some((el: EventTarget) => { if ("classList" in el) { return Array.from((el as Element).classList).includes( "pac-container" ); } return false; }); if (hasPacContainer) { e.preventDefault(); } }} >

And now it's working perfect! I waste a lot of time looking for fix it before I red your messages.

Hey Ricardo thanks for the kind message, very appreciated and glad this helped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Is this issue stale? Stale
Projects
None yet
Development

No branches or pull requests

7 participants