Skip to content

Commit

Permalink
IE fixes
Browse files Browse the repository at this point in the history
IE 11 blocks dispatch of all events on elements with `disabled`
attribute.
  • Loading branch information
dfreedm committed May 15, 2018
1 parent 28625d6 commit 6255cdb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/utils/gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@
let dy = Math.abs(e.clientY - this.info.y);
// find original target from `preventer` for TouchEvents, or `e` for MouseEvents
let t = Gestures._findOriginalTarget(/** @type {Event} */(preventer || e));
if (!t || (canBeDisabled[/** @type {!HTMLElement} */(t).localName] && t.disabled)) {
if (!t || (canBeDisabled[/** @type {!HTMLElement} */(t).localName] && t.hasAttribute('disabled'))) {
return;
}
// dx,dy can be NaN if `click` has been simulated and there was no `down` for `start`
Expand Down
6 changes: 4 additions & 2 deletions test/unit/gestures-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@
}
static get properties() {
return {
disabled: Boolean
disabled: {
type: Boolean,
reflectToAttribute: true
}
};
}
constructor() {
Expand Down Expand Up @@ -303,7 +306,6 @@
</optgroup>
</select>
<textarea></textarea>
<div></div>
</template>
<script>
class AllDisabled extends Polymer.GestureEventListeners(Polymer.Element) {
Expand Down
33 changes: 30 additions & 3 deletions test/unit/gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,30 @@
});

suite('disabled', function() {
test('click() function works as expected on disabled elements', function() {
let shouldSkip = true;

suiteSetup(function() {
/*
* IE 11 does not dispatch events to elements with `disabled` attribute
* This is different from all other browsers, so skip these tests in IE 11
*/
const div = document.createElement('div');
div.setAttribute('disabled', '');
document.body.appendChild(div);
div.addEventListener('click', () => {
shouldSkip = false;
});
div.click();
document.body.removeChild(div);
});
setup(function() {
Polymer.Gestures.resetMouseCanceller();
});

test('click() function works as expected on disabled elements', function() {
if (shouldSkip) {
this.skip();
}
let el = document.createElement('x-disabled-tap');
document.body.appendChild(el);
el.$.disabled.click();
Expand All @@ -628,6 +650,9 @@
});

test('disabled elements don\'t fire taps', function() {
if (shouldSkip) {
this.skip();
}
let el = document.createElement('x-disabled-tap');
document.body.appendChild(el);
// tap an element with disabled attribute
Expand Down Expand Up @@ -666,6 +691,8 @@
target.dispatchEvent(touchend);
assert.deepEqual(el.taps, ['button#nested']);

Polymer.Gestures.resetMouseCanceller();

// tap a custom element with a `disabled` property
target = el.$.disabledEl;
// simulate the event sequence of a touch on the screen
Expand All @@ -686,11 +713,11 @@
document.body.removeChild(el);
});

test('test all "disablable" elements', function() {
test('test all "disableable" elements', function() {
const el = document.createElement('all-disabled');
document.body.appendChild(el);
el.tapAll();
assert.deepEqual(el.taps, ['div']);
assert.deepEqual(el.taps, []);
document.body.removeChild(el);
});
});
Expand Down

0 comments on commit 6255cdb

Please sign in to comment.