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

sl-select does not close when clicking outside #1859

Closed
Antony92 opened this issue Feb 8, 2024 · 2 comments · Fixed by #1878 or patooworld/nginx-1.25.4#4 · May be fixed by patooworld/pwa-starter#4, patooworld/nginx-1.25.4#11 or TaylorBundy/swiper#3
Labels
bug Things that aren't working right in the library.

Comments

@Antony92
Copy link

Antony92 commented Feb 8, 2024

Describe the bug

It seems that adding sl-select in shadowDOM breaks the close outside functionality. This was not present in version 2.12 and started to happen in 2.13 due to this PR

To Reproduce

Steps to reproduce the behavior:

  1. Add sl-select with some options in a Lit component
  2. Click on the sl-select to open the list of options
  3. Try to click outside the sl-select
  4. List of options does not close

Demo

CodePen

Browser / OS

  • OS: Mac
  • Browser: Chrome
  • Browser version: 121

Additional information

Most likely the issue is from switching document to getRootNode()

    //
    // Listen on the root node instead of the document in case the elements are inside a shadow root
    //
    // https://github.com/shoelace-style/shoelace/issues/1763
    //
    const root = this.getRootNode();
@Antony92 Antony92 added the bug Things that aren't working right in the library. label Feb 8, 2024
@Antony92
Copy link
Author

Antony92 commented Feb 8, 2024

After checking the code maybe focusin should stay to this.getRootNode() in order for the previous issue with the tab focus to remain fixed, but keydown and mousedown to remain on the document ?

root.addEventListener('focusin', this.handleDocumentFocusIn);
document.addEventListener('keydown', this.handleDocumentKeyDown);
document.addEventListener('mousedown', this.handleDocumentMouseDown);

@claviska

@Antony92
Copy link
Author

PR created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment