-
Notifications
You must be signed in to change notification settings - Fork 933
-
Notifications
You must be signed in to change notification settings - Fork 933
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
Cannot click on items within useSelect when mounted in the shadow DOM #1622
Comments
Not sure why would you need this usage, with the button in the li that has the onclick which uses an imperative function. I'm not in favour of changing our code to account for all kinds of usages that could come up. Clicking the li should change your selected item. So why doing the button thing? |
Since 2020, we're using |
I have the same issue with We tried to solve this via the environment prop, but then the list does not open when you initially click into the field. environment: {
addEventListener: shadowRoot.addEventListener.bind(shadowRoot),
removeEventListener: shadowRoot.removeEventListener.bind(root),
document,
Node,
}, |
downshift
version: 9.0.8node
version: 20.15.1npm
(oryarn
) version: npm@10.7.0Relevant code or config
https://github.com/pzaczkiewicz-athenahealth/downshift-shadow-dom-bug
What you did:
Define DownshiftSelect based on default usage such that instead of relying on
selectedItem
fromuseSelect
, has a<button onClick={() => setSelectedItem(item)}>{item}</button>
. Wrap that in a shadow root.What happened:
The button's onClick will never fire.
Reproduction repository:
https://github.com/pzaczkiewicz-athenahealth/downshift-shadow-dom-bug
Problem description:
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.While I can define my own
environment
object rooted on the shadow Root, that would cause clicks in the light DOM to not close the Select.Suggested solution:
Instead of event.target, use
event.composedPath()[0]
, as that will drill into the shadow DOM. This implementation will still work if there is no shadow DOM.The text was updated successfully, but these errors were encountered: