Skip to content

Commit

Permalink
Merge pull request #17874 from simonihmig/fix-stop-propagation
Browse files Browse the repository at this point in the history
[BUGFIX beta] Fix no-jQuery EventDispatcher to prevent events bubbling up when event.stopPropagation() was called
  • Loading branch information
chancancode authored Apr 7, 2019
2 parents 7da998b + 561759e commit fb416b0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { alias } from '@ember/-internals/metal';
import { subscribe, reset } from '@ember/instrumentation';
import { Route, NoneLocation } from '@ember/-internals/routing';
import { EMBER_IMPROVED_INSTRUMENTATION } from '@ember/canary-features';
import { jQueryDisabled } from '@ember/-internals/views';

if (EMBER_GLIMMER_ANGLE_BRACKET_BUILT_INS) {
// IE includes the host name
Expand Down Expand Up @@ -882,12 +881,7 @@ if (EMBER_GLIMMER_ANGLE_BRACKET_BUILT_INS) {
.then(() => {
assert.equal(this.$('#contact').text(), 'Contact', 'precond - the link worked');

if (jQueryDisabled) {
// BUG: https://github.com/emberjs/ember.js/issues/17840
assert.equal(hidden, 1, 'The link bubbled anyway');
} else {
assert.strictEqual(hidden, 0, "The link didn't bubble");
}
assert.equal(hidden, 0, "The link didn't bubble");
});
}

Expand Down Expand Up @@ -938,13 +932,7 @@ if (EMBER_GLIMMER_ANGLE_BRACKET_BUILT_INS) {
})
.then(() => {
assert.equal(this.$('#contact').text(), 'Contact', 'precond - the link worked');

if (jQueryDisabled) {
// BUG: https://github.com/emberjs/ember.js/issues/17840
assert.equal(hidden, 1, 'The link bubbled anyway');
} else {
assert.strictEqual(hidden, 0, "The link didn't bubble");
}
assert.equal(hidden, 0, "The link didn't bubble");
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { alias } from '@ember/-internals/metal';
import { subscribe, reset } from '@ember/instrumentation';
import { Route, NoneLocation } from '@ember/-internals/routing';
import { EMBER_IMPROVED_INSTRUMENTATION } from '@ember/canary-features';
import { jQueryDisabled } from '@ember/-internals/views';

// IE includes the host name
function normalizeUrl(url) {
Expand Down Expand Up @@ -862,12 +861,7 @@ moduleFor(
.then(() => {
assert.equal(this.$('#contact').text(), 'Contact', 'precond - the link worked');

if (jQueryDisabled) {
// BUG: https://github.com/emberjs/ember.js/issues/17840
assert.equal(hidden, 1, 'The link bubbled anyway');
} else {
assert.strictEqual(hidden, 0, "The link didn't bubble");
}
assert.equal(hidden, 0, "The link didn't bubble");
});
}

Expand Down Expand Up @@ -918,13 +912,7 @@ moduleFor(
})
.then(() => {
assert.equal(this.$('#contact').text(), 'Contact', 'precond - the link worked');

if (jQueryDisabled) {
// BUG: https://github.com/emberjs/ember.js/issues/17840
assert.equal(hidden, 1, 'The link bubbled anyway');
} else {
assert.strictEqual(hidden, 0, "The link didn't bubble");
}
assert.equal(hidden, 0, "The link didn't bubble");
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ moduleFor(
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
}

['@test events bubbling up can be prevented'](assert) {
['@test events bubbling up can be prevented by returning false'](assert) {
let hasReceivedEvent;

this.registerComponent('x-foo', {
Expand All @@ -133,6 +133,33 @@ moduleFor(
assert.notOk(hasReceivedEvent, 'change event has not been received');
}

['@test events bubbling up can be prevented by calling stopPropagation()'](assert) {
let hasReceivedEvent;

this.registerComponent('x-foo', {
ComponentClass: Component.extend({
change() {
hasReceivedEvent = true;
},
}),
template: `{{yield}}`,
});

this.registerComponent('x-bar', {
ComponentClass: Component.extend({
change(e) {
e.stopPropagation();
},
}),
template: `<input id="is-done" type="checkbox">`,
});

this.render(`{{#x-foo}}{{x-bar}}{{/x-foo}}`);

runTask(() => this.$('#is-done').trigger('change'));
assert.notOk(hasReceivedEvent, 'change event has not been received');
}

['@test event handlers are wrapped in a run loop'](assert) {
this.registerComponent('x-foo', {
ComponentClass: Component.extend({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ export default EmberObject.extend({
event.preventDefault();
event.stopPropagation();
break;
} else if (event.cancelBubble === true) {
break;
}
} else if (target.hasAttribute('data-ember-action')) {
if (actionHandler(target, event) === false) {
Expand Down

0 comments on commit fb416b0

Please sign in to comment.