ui icon indicating copy to clipboard operation
ui copied to clipboard

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

Open tegarmonster opened this issue 1 year ago • 4 comments

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

tegarmonster avatar Dec 25 '23 13:12 tegarmonster

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?

lucasprins avatar Dec 25 '23 19:12 lucasprins

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

<Sheet>
  <MapComponent />
</Sheet>

tegarmonster avatar Dec 26 '23 07:12 tegarmonster

@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 avatar Jan 12 '24 22:01 kaydenthomson

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()
  }
}}

kaydenthomson avatar Jan 13 '24 00:01 kaydenthomson

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 avatar Feb 28 '24 23:02 shadcn

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 https://github.com/radix-ui/primitives/issues/1859#issuecomment-1771356816, 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);
  }, []);

dertuman avatar May 16 '24 13:05 dertuman

thanks @kaydenthomson and @dertuman !

tegarmonster avatar Jun 24 '24 06:06 tegarmonster