Skip to content

Commit

Permalink
dispatch a change event on user action
Browse files Browse the repository at this point in the history
Implementation is aligned with `input type=checkbox` as it is only
fired when the user changes the value by interacting with the component

Fixes #81
  • Loading branch information
manolo committed May 16, 2018
1 parent ee4a3f9 commit 40026ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/vaadin-checkbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@

_toggleChecked() {
this.checked = !this.checked;
this.dispatchEvent(new CustomEvent('change', {composed: true, bubbles: true}));
}
}

Expand Down
25 changes: 24 additions & 1 deletion test/vaadin-checkbox_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,30 @@
});
});

describe('change-event', () => {
let vaadinCheckbox;

beforeEach(() => vaadinCheckbox = fixture('default'));

it('should not fire change-event when changing checked value programatically', () => {
vaadinCheckbox.addEventListener('change', () => {
throw new Error('Should not come here!');
});
vaadinCheckbox.checked = true;
});

it('should fire change-event when user checks the element', done => {
vaadinCheckbox.addEventListener('change', () => done());
vaadinCheckbox.click();
});

it('should fire change-event when user unchecks the element', done => {
vaadinCheckbox.checked = true;
vaadinCheckbox.addEventListener('change', () => done());
vaadinCheckbox.click();
});
});

describe('iron-form-checkbox', () => {
let boundNameCheckbox, attrNameCheckbox, form;

Expand Down Expand Up @@ -276,7 +300,6 @@
attrNameCheckbox.checked = true;
expect(form.serializeForm().attrcheckbox).to.equal('on');
});

});
</script>
</body>

0 comments on commit 40026ab

Please sign in to comment.