Skip to content

Commit

Permalink
Merge pull request #51 from PolymerElements/paper-menu-89
Browse files Browse the repository at this point in the history
Prevent retargeting of events from shadow descendants of light children.
  • Loading branch information
bicknellr committed May 5, 2016
2 parents c1d38a2 + aa1e6e0 commit 319f828
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion iron-control-state.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@

if (event.target === this) {
this._setFocused(event.type === 'focus');
} else if (!this.shadowRoot && !this.isLightDescendant(event.target)) {
} else if (!this.shadowRoot &&
!this.isLightDescendant(Polymer.dom(event).localTarget)) {
this.fire(event.type, {sourceEvent: event}, {
node: this,
bubbles: event.bubbles,
Expand Down
19 changes: 17 additions & 2 deletions test/focused-state.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
</template>
</test-fixture>

<test-fixture id="LightDOM">
<test-fixture id="LightDOM">
<template>
<test-light-dom>
<input id="input">
<nested-focusable></nested-focusable>
</test-light-dom>
</template>
</test-fixture>
Expand Down Expand Up @@ -119,11 +120,13 @@


suite('elements in the light dom', function() {
var lightDOM, input;
var lightDOM, input, lightDescendantShadowInput;

setup(function() {
lightDOM = fixture('LightDOM');
input = document.querySelector('#input');
lightDescendantShadowInput = Polymer.dom(lightDOM)
.querySelector('nested-focusable').$.input;
});

test('should not fire the focus event', function() {
Expand All @@ -138,6 +141,18 @@
expect(nFocusEvents).to.be.equal(0);
});

test('should not fire the focus event from shadow descendants', function() {
var nFocusEvents = 0;

lightDOM.addEventListener('focus', function() {
nFocusEvents += 1;
});

MockInteractions.focus(lightDescendantShadowInput);

expect(nFocusEvents).to.be.equal(0);
});

});

</script>
Expand Down

0 comments on commit 319f828

Please sign in to comment.