Skip to content

Commit 0914f3d

Browse files
fix: set initial value using property to ensure change is fired (#6606) (#6609)
Co-authored-by: Serhii Kulykov <[email protected]>
1 parent 4127e99 commit 0914f3d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/field-base/src/input-controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class InputController extends SlotController {
1616
() => document.createElement('input'),
1717
(host, node) => {
1818
if (host.value) {
19-
node.setAttribute('value', host.value);
19+
node.value = host.value;
2020
}
2121
if (host.type) {
2222
node.setAttribute('type', host.type);

packages/field-base/test/input-controller.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { expect } from '@esm-bundle/chai';
22
import { fixtureSync } from '@vaadin/testing-helpers';
3+
import { sendKeys } from '@web/test-runner-commands';
4+
import sinon from 'sinon';
35
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
46
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
57
import { InputController } from '../src/input-controller.js';
@@ -71,6 +73,21 @@ describe('input-controller', () => {
7173
input = element.querySelector('[slot=input]');
7274
expect(input.value).to.equal('foo');
7375
});
76+
77+
it('should dispatch change event when clearing input', async () => {
78+
element.addController(new InputController(element));
79+
input = element.querySelector('[slot=input]');
80+
81+
const spy = sinon.spy();
82+
input.addEventListener('change', spy);
83+
84+
input.focus();
85+
input.select();
86+
await sendKeys({ press: 'Backspace' });
87+
input.blur();
88+
89+
expect(spy.calledOnce).to.be.true;
90+
});
7491
});
7592

7693
describe('type property', () => {

0 commit comments

Comments
 (0)