From 7925254bec1cf924ddf9da0c34ec9b612eb0b22d Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Mon, 22 Apr 2019 11:08:18 -0700 Subject: [PATCH] Fix `localTareget` when `ShadyDOM.noPatch` is in use Fixes #5526. Return the "lowest" element in the same root as the node listening for the event (currentTarget). --- lib/legacy/polymer.dom.js | 13 ++++++++++++- test/unit/polymer-dom-nopatch.html | 21 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/legacy/polymer.dom.js b/lib/legacy/polymer.dom.js index 478bbc9665..ff4fac8820 100644 --- a/lib/legacy/polymer.dom.js +++ b/lib/legacy/polymer.dom.js @@ -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 }, diff --git a/test/unit/polymer-dom-nopatch.html b/test/unit/polymer-dom-nopatch.html index 066c7463aa..96faf2dfd1 100644 --- a/test/unit/polymer-dom-nopatch.html +++ b/test/unit/polymer-dom-nopatch.html @@ -47,7 +47,9 @@