Skip to content

Commit

Permalink
fix: set initial value using property to ensure change is fired (#6606)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Oct 6, 2023
1 parent 010438d commit 0ae8807
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/field-base/src/input-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class InputController extends SlotController {
super(host, 'input', 'input', {
initializer: (node, host) => {
if (host.value) {
node.setAttribute('value', host.value);
node.value = host.value;
}
if (host.type) {
node.setAttribute('type', host.type);
Expand Down
17 changes: 17 additions & 0 deletions packages/field-base/test/input-controller.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync } from '@vaadin/testing-helpers';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
import { InputController } from '../src/input-controller.js';
Expand Down Expand Up @@ -71,6 +73,21 @@ describe('input-controller', () => {
input = element.querySelector('[slot=input]');
expect(input.value).to.equal('foo');
});

it('should dispatch change event when clearing input', async () => {
element.addController(new InputController(element));
input = element.querySelector('[slot=input]');

const spy = sinon.spy();
input.addEventListener('change', spy);

input.focus();
input.select();
await sendKeys({ press: 'Backspace' });
input.blur();

expect(spy).to.be.calledOnce;
});
});

describe('type property', () => {
Expand Down

0 comments on commit 0ae8807

Please sign in to comment.