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

Fix localTarget when ShadyDOM.noPatch is in use #5527

Merged
merged 1 commit into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/legacy/polymer.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,20 @@ if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noP

Object.defineProperties(EventApi.prototype, {

// Returns the "lowest" node in the same root as the event's currentTarget.
// When in `noPatch` mode, this must be calculated by walking the event's
// path.
localTarget: {
get() {
return this.event.currentTarget;
const current = this.event.currentTarget;
const currentRoot = current && dom(current).getOwnerRoot();
const p$ = this.path;
for (let i = 0; i < p$.length; i++) {
const e = p$[i];
if (dom(e).getOwnerRoot() === currentRoot) {
return e;
}
}
},
configurable: true
},
Expand Down
21 changes: 18 additions & 3 deletions test/unit/polymer-dom-nopatch.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

<dom-module id="x-event-scoped">
<template>
<div id="scoped"></div>
<div id="container">
<div id="scoped"></div>
</div>
</template>
<script type="module">
import { Polymer } from '../../polymer-legacy.js';
Expand Down Expand Up @@ -189,7 +191,7 @@

suite('events', function() {

test('localTarget, rootTarget, path', function(done) {
test('localTarget, rootTarget, path', function() {
// skip if noPatch is not available
if (!window.ShadyDOM.wrap) {
this.skip();
Expand All @@ -207,7 +209,20 @@
nodes.push(window);
const path = dom(e).path;
assert.deepEqual(path, nodes);
done();
});
ShadyDOM.flush();
el.fireComposed();
});

test('localTarget when target node and event listener node are distinct', function() {
// skip if noPatch is not available
if (!window.ShadyDOM.wrap) {
this.skip();
}
var el = fixture('scoped');
el.$.container.addEventListener('composed', function(e) {
assert.equal(dom(e).rootTarget, el.$.scoped);
assert.equal(dom(e).localTarget, el.$.scoped);
});
ShadyDOM.flush();
el.fireComposed();
Expand Down