Skip to content

Commit

Permalink
fix: call click on checkbox Space key up (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Nov 8, 2023
1 parent ad4fbe6 commit 7cc4752
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/vaadin-checkbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,8 @@
this.addEventListener('keyup', e => {
if (this.__interactionsAllowed(e) && e.keyCode === 32) {
e.preventDefault();
this._toggleChecked();
this.click();
this.removeAttribute('active');

if (this.indeterminate) {
this.indeterminate = false;
}
}
});
}
Expand Down
10 changes: 10 additions & 0 deletions test/vaadin-checkbox_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@
expect(vaadinCheckbox.getAttribute('aria-checked')).to.be.eql('true');
});

it('should fire click event on space key press', () => {
const spy = sinon.spy();
vaadinCheckbox.addEventListener('click', spy);

MockInteractions.keyDownOn(vaadinCheckbox, 32);
MockInteractions.keyUpOn(vaadinCheckbox, 32);

expect(spy).to.be.calledOnce;
});

it('should not be checked after space when initially checked is true and indeterminate is true', () => {
vaadinCheckbox.checked = true;
vaadinCheckbox.indeterminate = true;
Expand Down

0 comments on commit 7cc4752

Please sign in to comment.