Skip to content

Commit

Permalink
Removes special case for "legend" elements on dom.triggerEvent
Browse files Browse the repository at this point in the history
Firefox doesn't follow this rule for "legend" elements, so we shouldn't force it on our system.
  • Loading branch information
mairatma committed Aug 31, 2016
1 parent 425af89 commit 9d402a2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 73 deletions.
2 changes: 1 addition & 1 deletion packages/metal-dom/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class dom {
var matchesSelector = 'button, input, select, textarea, fieldset';

if (eventName === 'click') {
while (currElement && currElement.tagName !== 'LEGEND') {
while (currElement) {
if (currElement.disabled && dom.match(currElement, matchesSelector)) {
isAble = false;
break;
Expand Down
72 changes: 0 additions & 72 deletions packages/metal-dom/test/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,78 +695,6 @@ describe('dom', function() {
assert.strictEqual(0, listener3.callCount);
assert.strictEqual(0, listener4.callCount);
});

it('it should trigger delegate click event on elements wrapped by a "legend" tag and with disabled parent', function() {
var fieldset = document.createElement('fieldset');
var legend = document.createElement('legend');
fieldset.disabled = true;
fieldset.appendChild(legend);
document.body.appendChild(fieldset);

var input = document.createElement('input');
var select = document.createElement('select');
var button = document.createElement('button');
var textarea = document.createElement('textarea');
legend.appendChild(input);
legend.appendChild(select);
legend.appendChild(button);
legend.appendChild(textarea);

var listener1 = sinon.stub();
var listener2 = sinon.stub();
var listener3 = sinon.stub();
var listener4 = sinon.stub();

dom.delegate(fieldset, 'click', input, listener1);
dom.delegate(fieldset, 'click', select, listener2);
dom.delegate(fieldset, 'click', button, listener3);
dom.delegate(fieldset, 'click', textarea, listener4);

dom.triggerEvent(input, 'click');
dom.triggerEvent(select, 'click');
dom.triggerEvent(button, 'click');
dom.triggerEvent(textarea, 'click');
assert.strictEqual(1, listener1.callCount);
assert.strictEqual(1, listener2.callCount);
assert.strictEqual(1, listener3.callCount);
assert.strictEqual(1, listener4.callCount);
});

it('should not trigger delegate click event to an element which its valid parent is disabled even it is wrapped by another element different of legend', function() {
var fieldset = document.createElement('fieldset');
var wrapper = document.createElement('div');
fieldset.disabled = true;
fieldset.appendChild(wrapper);
document.body.appendChild(fieldset);

var input = document.createElement('input');
var select = document.createElement('select');
var button = document.createElement('button');
var textarea = document.createElement('textarea');
wrapper.appendChild(input);
wrapper.appendChild(select);
wrapper.appendChild(button);
wrapper.appendChild(textarea);

var listener1 = sinon.stub();
var listener2 = sinon.stub();
var listener3 = sinon.stub();
var listener4 = sinon.stub();

dom.delegate(fieldset, 'click', input, listener1);
dom.delegate(fieldset, 'click', select, listener2);
dom.delegate(fieldset, 'click', button, listener3);
dom.delegate(fieldset, 'click', textarea, listener4);

dom.triggerEvent(input, 'click');
dom.triggerEvent(select, 'click');
dom.triggerEvent(button, 'click');
dom.triggerEvent(textarea, 'click');
assert.strictEqual(0, listener1.callCount);
assert.strictEqual(0, listener2.callCount);
assert.strictEqual(0, listener3.callCount);
assert.strictEqual(0, listener4.callCount);
});
});

describe('without selector', function() {
Expand Down

0 comments on commit 9d402a2

Please sign in to comment.