Skip to content

Fix event handling in a Shadow DOM#1647

Open
sbaechler wants to merge 4 commits intodownshift-js:masterfrom
ti8m:shadow-dom-patch
Open

Fix event handling in a Shadow DOM#1647
sbaechler wants to merge 4 commits intodownshift-js:masterfrom
ti8m:shadow-dom-patch

Conversation

@sbaechler
Copy link

@sbaechler sbaechler commented May 13, 2025

What:

This fix adds a traversal through shadow roots to fix a long standing issue that Downshift is not properly working when rendered inside of a shadow DOM.

Fixes #1622

Why:

useMouseAndTouchTracker adds a bunch of event listeners to document in order to tell if the Select is open or not, but event.target represents the last <div> in the light DOM, rather than the <li> within the shadow DOM. Thus, targetWithinDownshift always fails, and the Select is closed before the button's onClick is able to be called.

How:

The utility function targetWithinDownshift now iterates through shadow roots to find the real active element.

I also added a Cypress test to reproduce the issue in (/shadow-dom/useMultipleCombobox) as well as a few unittests.

We did have a patch for version 6 that also patched the tab order. However, in my manual tests in version 9 I did not see any issues with the tab order anymore.

Checklist:

  • Documentation N/A
  • Tests
  • TypeScript Types N/A
  • Flow Types N/A
  • Ready to be merged

I could not get the pre-commit hooks to pick up the proper test and format configuration. It might need some reformatting.

@sbaechler sbaechler force-pushed the shadow-dom-patch branch 2 times, most recently from 3a4988b to 40a575d Compare May 13, 2025 11:16
@sbaechler sbaechler marked this pull request as draft May 14, 2025 07:24
@sbaechler sbaechler marked this pull request as ready for review May 14, 2025 18:22
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

Successfully merging this pull request may close these issues.

Cannot click on items within useSelect when mounted in the shadow DOM

1 participant