Skip to content

Commit

Permalink
fix: clear value when removing the last input (#8270) (#8277)
Browse files Browse the repository at this point in the history
Co-authored-by: Ugur Saglam <106508695+ugur-vaadin@users.noreply.github.com>
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent 642df30 commit 4b7db8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/custom-field/src/vaadin-custom-field-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ export const CustomFieldMixin = (superClass) =>
/** @private */
__inputsChanged(inputs, oldInputs) {
if (inputs.length === 0) {
if (oldInputs && oldInputs.length > 0) {
this.__setValue();
}
return;
}

Expand Down
13 changes: 13 additions & 0 deletions packages/custom-field/test/custom-field.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ describe('custom field', () => {
expect(el.value).to.equal('');
});
});

it('should update value when removing inputs', async () => {
customField.value = '1\t1';
await nextUpdate(customField);

customField.removeChild(customField.inputs[0]);
await nextUpdate(customField);
expect(customField.value).to.equal('1');

customField.removeChild(customField.inputs[0]);
await nextUpdate(customField);
expect(customField.value).to.equal('');
});
});

describe('value set with attribute', () => {
Expand Down

0 comments on commit 4b7db8b

Please sign in to comment.