Skip to content

Commit

Permalink
fix: set has-value attribute on radio-button click (#2862)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Oct 14, 2021
1 parent 8a6f105 commit 81543e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
4 changes: 0 additions & 4 deletions packages/radio-group/src/vaadin-radio-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,6 @@ class RadioGroup extends FieldMixin(FocusMixin(DisabledMixin(KeyboardMixin(DirMi
return;
}

if (this.__selectedRadioButton && this.__selectedRadioButton.value === newValue) {
return;
}

const newSelectedRadioButton = this.__radioButtons.find((radioButton) => {
return radioButton.value === newValue;
});
Expand Down
42 changes: 31 additions & 11 deletions packages/radio-group/test/radio-group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,6 @@ describe('radio-group', () => {
expect(buttons[1].checked).to.be.false;
});

it('should not have has-value attribute by default', () => {
expect(group.hasAttribute('has-value')).to.be.false;
});

it('should toggle has-value attribute on value change', () => {
group.value = '2';
expect(group.hasAttribute('has-value')).to.be.true;
group.value = '';
expect(group.hasAttribute('has-value')).to.be.false;
});

it('should dispatch value-changed event when value changes', () => {
const spy = sinon.spy();
group.addEventListener('value-changed', spy);
Expand All @@ -302,6 +291,37 @@ describe('radio-group', () => {
});
});

describe('has-value attribute', () => {
beforeEach(async () => {
group = fixtureSync(`
<vaadin-radio-group>
<vaadin-radio-button value="1" label="Button 1"></vaadin-radio-button>
<vaadin-radio-button value="2" label="Button 2"></vaadin-radio-button>
</vaadin-radio-group>
`);
await nextFrame();
buttons = [...group.querySelectorAll('vaadin-radio-button')];
});

it('should not have has-value attribute by default', () => {
expect(group.hasAttribute('has-value')).to.be.false;
});

it('should set has-value on radio button click', () => {
buttons[0].click();
expect(group.hasAttribute('has-value')).to.be.true;
buttons[1].click();
expect(group.hasAttribute('has-value')).to.be.true;
});

it('should toggle has-value attribute on value change', () => {
group.value = '2';
expect(group.hasAttribute('has-value')).to.be.true;
group.value = '';
expect(group.hasAttribute('has-value')).to.be.false;
});
});

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

Expand Down

0 comments on commit 81543e0

Please sign in to comment.