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

Popover not detecting content click events (links / otherwise) in web component context (with fix) #175

Open
cjm771 opened this issue Jan 25, 2024 · 2 comments

Comments

@cjm771
Copy link

cjm771 commented Jan 25, 2024

Describe the bug

The issue is when using web components export (we use this to embed svelte in legacy pages), the mousedown event for popovers (likely modals as well) aren't checking for shadowroot target, adding check for composedPath() from event does actually cehck the correct target, where as the typical event.target defaults to the top level container as a web component. See below fix

function handleMousedown(event) {
    let target = event.target;
    if (popoverState !== PopoverStates.Open) return;
    if ($button?.contains(target)) return;
    if ($panel?.contains(target)) return;
   
   // below two lines are a fix that seems to work
    const potentialShadowRootTarget = event.composedPath()[0]; 
    if ($panel?.contains(potentialShadowRootTarget)) return;
     
     $api.closePopover();
}

To Reproduce
simply put a link in the content of a popoverPanel, and make sure the bundling uses customElement: true. (svelte dev api - web components) below is our example loader an

Snippet inside PopoverPanel

Here is a <a href="http://google.com" target="_blank"><Button link>google link.</Button></a>. Can you click it? it should not register this inside web component shadow root context

Webpack config (customElement: true)

    {
            loader: 'svelte-loader',
            options: {
              compilerOptions: {
                dev: !IS_PROD,
                customElement: true,
              },
              emitCss: true,
              hotReload: false,
              preprocess: sveltePreprocess({
                postcss: {
                  plugins: [tailwindcss],
                },
                sourceMap: false,
              }),
            },
          },

Library version
1.0.2

@cjm771
Copy link
Author

cjm771 commented Jan 25, 2024

For the time being a workaround if you can afford it is to on:mousedown={(e) => { e.stopPropagation() } on a menu item or popoverpanel main container div

@LeoCaprile
Copy link

LeoCaprile commented Feb 2, 2024

I think you can also doon:mousedown|stopPropagation={handleMouseDown}

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

No branches or pull requests

2 participants