diff --git a/src/vaadin-radio-button.html b/src/vaadin-radio-button.html index c80e637..aeeb8b2 100644 --- a/src/vaadin-radio-button.html +++ b/src/vaadin-radio-button.html @@ -50,7 +50,7 @@ { const checkedChangedListener = e => { if (e.target.checked) { @@ -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' @@ -346,7 +345,7 @@ } _changeSelectedButton(button, fireChangeEvent) { - if (this._checkedButton === button) { + if (this._checkedButton === button && !this.isKeyDown) { return; } @@ -371,6 +370,7 @@ this.validate(); this.readonly && this._updateDisableButtons(); button && this._setFocusable(this._radioButtons.indexOf(button)); + this.isKeyDown = false; } _valueChanged(newV, oldV) { diff --git a/test/vaadin-radio-group.html b/test/vaadin-radio-group.html index 4cb1ce1..4e2cf76 100644 --- a/test/vaadin-radio-group.html +++ b/test/vaadin-radio-group.html @@ -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); + }); }); });