Skip to content

Commit

Permalink
Don't dispatch click event for disabled button
Browse files Browse the repository at this point in the history
  • Loading branch information
samiheikki committed Dec 12, 2018
1 parent aba708b commit 657ea5b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/vaadin-button.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@
get focusElement() {
return this.$.button;
}

/**
* @protected
*/
click() {
if (!this.disabled) {
super.click();
}
}
}

customElements.define(ButtonElement.is, ButtonElement);
Expand Down
3 changes: 2 additions & 1 deletion test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"it": false,
"expect": false,
"gemini": false,
"MockInteractions": false
"MockInteractions": false,
"sinon": false
}
}
15 changes: 15 additions & 0 deletions test/vaadin-button_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@
MockInteractions.downAndUp(vaadinButton);
});

it('should fire click event for button', () => {
const spy = sinon.spy();
vaadinButton.addEventListener('click', spy);
vaadinButton.click();
expect(spy.called).to.be.true;
});

it('should not fire click event for disabled button', () => {
const spy = sinon.spy();
vaadinButton.disabled = true;
vaadinButton.addEventListener('click', spy);
vaadinButton.click();
expect(spy.called).to.be.false;
});

it('host should have the `button` role', () => {
expect(vaadinButton.getAttribute('role')).to.be.eql('button');
});
Expand Down

0 comments on commit 657ea5b

Please sign in to comment.