-
Notifications
You must be signed in to change notification settings - Fork 971
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
Don't fire events if you're inside a textfield/input in a shadow DOM #254
Don't fire events if you're inside a textfield/input in a shadow DOM #254
Conversation
Use `event.path` (if it's available) to get the target element, so the `stopCallback` function supports events occuring in a shadow DOM. Fixes #245
@@ -598,7 +598,8 @@ | |||
function _fireCallback(callback, e, combo, sequence) { | |||
|
|||
// if this event should not happen stop here | |||
if (self.stopCallback(e, e.target || e.srcElement, combo, sequence)) { | |||
var element = typeof e.path == 'object' && e.path.constructor == Array ? e.path[0] : e.target || e.srcElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the typeof
check and constructor check can you please update to use ===
Also I just checked and the second test now no longer runs via phantom js
Is this just a matter of updating mocha/phantomjs or is this a known thing? |
That's a bit weird. I was sure I had that test running fine in both browser and phantom. I know the polymer guys use mocha for testing, so I guess it'll work if just the test libs are upgraded. I'll look into it. |
What currently is preventing this from being fixed? |
It would be amazing if this could be either merged or the underlying issue fixed. I tried monkey-patching mousetrap.js by adding the following just before the final return statement in // Events originating from a shadow DOM are re-targetted; thus, `e.target` is not always
// the initial event source. If the first element in the event’s composed path is not
// the target, it has a different initial event source than `element`.
if ('composedPath' in e && typeof e.composedPath === 'function') {
var initialEventTarget = e.composedPath()[0];
if (initialEventTarget !== e.target) {
element = initialEventTarget;
}
} This seems to work. Should I submit a pull request? |
@ccampbell I’m trying to write a test for my solution posted above and I get same error:
Mocha version 1.9.0 is used by these tests. That version is very outdated and doesn’t know about |
This issue was addressed in #445 and can be closed. |
Events occuring in a shadow DOM are retargeted to look like they come from the host element. Use
event.path
rather thanevent.target
to get the actual element in which the event occured.This pull request fixes #245.