-
-
Notifications
You must be signed in to change notification settings - Fork 7
fix: use composedPath
instead of target
, fixes #278
#279
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
Conversation
|
Playwright E2E Test Results78 tests 78 ✅ 1m 51s ⏱️ Results for commit 580b2ce. ♻️ This comment has been updated with latest results. |
@silvester-pari so just to be clear, should I assume correctly that in a non-shadow environment, then |
composedPath
instead of target
composedPath
instead of target
, fixes #278
@ghiscoding I think (not being an expert) that it equals to If you'd like to add an util function, something like function isInShadow(node) {
return node.getRootNode() instanceof ShadowRoot;
} could be used in order to determine if the element is currently used in a shadow root (see SO answer here). In this case I'd ask you to add the function or to provide guidance on structurizing this. |
ok after doing some googling too, it seems to always be filled on modern browser (available since Jan. 2020), but maybe just to be on the safe side we could do something like this external function protected getEventTarget(e: Event & { target: HTMLElement }) {
if (e.composedPath) {
return e.composedPath()[0] as HTMLElement;
}
return e.target as HTMLElement;
} and then call it everywhere you had composed path protected infiniteScrollHandler(e: (MouseEvent & { target: HTMLElement }) | null, idx?: number, fullCount?: number) {
const target = this.getEventTarget(e); if we have problem in the future, then we only have 1 function to fix :) Side note, I also found this article Handling web components and drag and drop with event.composedPath() interesting and makes me think that I should revisit my data grid library as well. |
I did as you suggested,
Edit: Sorry, this was because of a typo on my side! Thanks for the link, interesting read indeed! |
ok thanks even if it always goes into the first condition, I still find it cleaner with the external function :) So I assume that the PR is ready to be merged now and will go ahead, thanks again. |
I've pushed v3.2.2 release that includes your fix. Thanks for you contribution to the project 🎉 |
side note, if you like the lib, it would be nice to upvote it since it helps to make it more visible. Thanks |
This PR introduces
e.composedPath()[0]
as an alternative fore.target
to make the library usable inside a shadow DOM. Background: Because of Eventtarget
Retargeting usingevent.target
returns the ancestor (e.g. custom element) instead of the clicked element, resulting in erroneous behavior like closing the dropdown on click (see #278).All instances of `e.target' have been replaced. The built bundle was tested in the minimal reproduction example and provided the desired result (behavior of dropdown inside shadow DOM was the same as without shadow DOM).
Closes #278.