Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
Merge pull request #276 from web-padawan/fix/275
Browse files Browse the repository at this point in the history
Workaround broken composed flag for focus events in Firefox 61
  • Loading branch information
dfreedm committed Aug 16, 2018
2 parents 48c57d2 + 73dbd09 commit e30766a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/patch-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ let eventMixin = {
if (this.__composed === undefined) {
// if there's an original `composed` getter on the Event prototype, use that
if (composedGetter) {
this.__composed = composedGetter(this);
// TODO(web-padawan): see https://github.com/webcomponents/shadydom/issues/275
this.__composed = this.type === 'focusin' || this.type === 'focusout' || composedGetter(this);
// If the event is trusted, or `isTrusted` is not supported, check the list of always composed events
} else if (this.isTrusted !== false) {
this.__composed = alwaysComposed[this.type];
Expand Down
27 changes: 27 additions & 0 deletions tests/event-path.html
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,33 @@
el.parentNode.removeChild(el);
});

test('focusin and focusout events patched to be always composed', function() {
const theDiv = document.createElement('div');
theDiv.attachShadow({mode: 'open'});

const theInput = document.createElement('input');
theDiv.shadowRoot.appendChild(theInput);
document.body.appendChild(theDiv);

const dispatchMockEvent = function(type, target) {
// do not set composed to force patching needed for Firefox 61
const e = new CustomEvent(type);
target.dispatchEvent(e);
};

const focusinSpy = sinon.spy();
const focusoutSpy = sinon.spy();

theInput.addEventListener('focusin', focusinSpy);
theInput.addEventListener('focusout', focusoutSpy);

dispatchMockEvent('focusin', theInput);
dispatchMockEvent('focusout', theInput);

assert.isTrue(focusinSpy.firstCall.args[0].composed, 'focusin event should be always composed');
assert.isTrue(focusoutSpy.firstCall.args[0].composed, 'focusout event should be always composed');
});

const hasOnListenersOnPrototype = (function() {
let nativeHTMLElement =
(window['customElements'] && window['customElements']['nativeHTMLElement']) ||
Expand Down

0 comments on commit e30766a

Please sign in to comment.