Skip to content

Commit

Permalink
fix: change checked condition on button removal (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoCardoso committed Sep 9, 2020
1 parent b07a65d commit c4fb7ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/vaadin-radio-group.html
Expand Up @@ -210,7 +210,7 @@

this._filterRadioButtons(info.removedNodes).forEach(button => {
button.removeEventListener('checked-changed', checkedChangedListener);
if (button.checked) {
if (button == this._checkedButton) {
this.value = undefined;
}
});
Expand Down
28 changes: 28 additions & 0 deletions test/vaadin-radio-group.html
Expand Up @@ -618,6 +618,34 @@
vaadinRadioButtonGroup._observer.flush();
expect(vaadinRadioButtonGroup.value).to.not.be.equal('2');
});

it('should work if value is set immediately after removing and adding new children', () => {
const items = [
{id: '1', name: 'item_1'},
{id: '2', name: 'item_2'},
{id: '3', name: 'item_3'},
{id: '4', name: 'item_4'}
];
let buttonSelected = 0;
function removeAndAddChildrenAndSelectNext() {
Array.from(vaadinRadioButtonGroup.children).forEach(button => vaadinRadioButtonGroup.removeChild(button));
items.forEach(item => {
const radioButton = window.document.createElement('vaadin-radio-button');
radioButton.textContent = item.name;
radioButton.value = item.id;
vaadinRadioButtonGroup.appendChild(radioButton);
});
vaadinRadioButtonGroup.value = ++buttonSelected;
}

removeAndAddChildrenAndSelectNext();
vaadinRadioButtonGroup._observer.flush();
expect(+vaadinRadioButtonGroup.value).to.be.equal(buttonSelected);

removeAndAddChildrenAndSelectNext();
vaadinRadioButtonGroup._observer.flush();
expect(+vaadinRadioButtonGroup.value).to.be.equal(buttonSelected);
});
});

describe('radio-group-with-dom-repeat', () => {
Expand Down

0 comments on commit c4fb7ff

Please sign in to comment.