Skip to content

Commit

Permalink
Merge 180298f into e2c6697
Browse files Browse the repository at this point in the history
  • Loading branch information
Phan-ThanhDat committed Mar 2, 2020
2 parents e2c6697 + 180298f commit 0f7f9c9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/vaadin-radio-button.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<span part="radio">
<input
type="radio"
checked="{{checked::change}}"
checked="[[checked]]"
disabled$="[[disabled]]"
role="presentation"
on-change="_onChange"
Expand Down Expand Up @@ -260,6 +260,7 @@
}

_onChange(e) {
this.checked = e.target.checked;
// In the Shadow DOM, the `change` event is not leaked into the
// ancestor tree, so we must do this manually.
const changeEvent = new CustomEvent('change', {
Expand Down
6 changes: 3 additions & 3 deletions src/vaadin-radio-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@

ready() {
super.ready();

this._addListeners();

this._observer = new Polymer.FlattenedNodesObserver(this, info => {
const checkedChangedListener = e => {
if (e.target.checked) {
Expand Down Expand Up @@ -260,6 +258,7 @@

_addListeners() {
this.addEventListener('keydown', e => {
this.isKeyDown = true;
// if e.target is vaadin-radio-group then assign to checkedRadioButton currently checked radio button
var checkedRadioButton = (e.target == this) ? this._checkedButton : e.target;
const horizontalRTL = this.getAttribute('dir') === 'rtl'
Expand Down Expand Up @@ -346,7 +345,7 @@
}

_changeSelectedButton(button, fireChangeEvent) {
if (this._checkedButton === button) {
if (this._checkedButton === button && !this.isKeyDown) {
return;
}

Expand All @@ -371,6 +370,7 @@
this.validate();
this.readonly && this._updateDisableButtons();
button && this._setFocusable(this._radioButtons.indexOf(button));
this.isKeyDown = false;
}

_valueChanged(newV, oldV) {
Expand Down
41 changes: 41 additions & 0 deletions test/vaadin-radio-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,47 @@

expect(spy).to.not.be.called;
});

it('should value on the vaadin-radio-group is updated at the time when change is fired by clicking mouse', done => {
// Mouse
vaadinRadioButtonGroup.addEventListener('change', e => {
expect(vaadinRadioButtonGroup.value).to.equal(vaadinRadioButtonList[2].value);
done();
});
vaadinRadioButtonList[2].click();
});

it('should change event on radio-group includes updated value after clicking mouse', done => {
vaadinRadioButtonGroup.addEventListener('change', e => {
expect(e.target.textContent).to.equal(vaadinRadioButtonList[2].textContent);
expect(e.currentTarget.value).to.equal(vaadinRadioButtonList[2].value);
done();
});
vaadinRadioButtonList[2].click();
});

it('should value on the vaadin-radio-group is updated at the time when change is fired by pressing down', (done) => {
vaadinRadioButtonList[1].focus();
vaadinRadioButtonList[1].checked = true;
expect(vaadinRadioButtonGroup.value).to.equal(vaadinRadioButtonList[1].value);
// Key down
vaadinRadioButtonGroup.addEventListener('change', e => {
expect(vaadinRadioButtonGroup.value).to.equal(vaadinRadioButtonList[0].value);
done();
});
MockInteractions.keyDownOn(vaadinRadioButtonGroup, 37);
});

it('should change event on radio-group includes updated value after pressing key down', done => {
vaadinRadioButtonList[1].focus();
vaadinRadioButtonList[1].checked = true;
vaadinRadioButtonGroup.addEventListener('change', e => {
expect(e.target.textContent).to.equal(vaadinRadioButtonList[0].textContent);
expect(e.currentTarget.value).to.equal(vaadinRadioButtonList[0].value);
done();
});
MockInteractions.keyDownOn(vaadinRadioButtonGroup, 37);
});
});
});

Expand Down

0 comments on commit 0f7f9c9

Please sign in to comment.