diff --git a/packages/field/src/InteractionStateMixin.js b/packages/field/src/InteractionStateMixin.js index 945ab2d88..629c23453 100644 --- a/packages/field/src/InteractionStateMixin.js +++ b/packages/field/src/InteractionStateMixin.js @@ -24,15 +24,13 @@ export const InteractionStateMixin = dedupeMixin( type: Boolean, reflect: true, }, - /** - * True when user has typed in something in the input field. + * True when user has changed the value of the field. */ dirty: { type: Boolean, reflect: true, }, - /** * True when user has left non-empty field or input is prefilled. * The name must be seen from the point of view of the input field: @@ -112,9 +110,8 @@ export const InteractionStateMixin = dedupeMixin( * Since this method will be called twice in last mentioned scenario, it must stay idempotent. */ initInteractionState() { - if (this.constructor._isPrefilled(this.modelValue)) { - this.prefilled = true; - } + this.dirty = false; + this.prefilled = this.constructor._isPrefilled(this.modelValue); } /** diff --git a/packages/field/test-suites/InteractionStateMixin.suite.js b/packages/field/test-suites/InteractionStateMixin.suite.js index 10c0b3f77..e60f8efa1 100644 --- a/packages/field/test-suites/InteractionStateMixin.suite.js +++ b/packages/field/test-suites/InteractionStateMixin.suite.js @@ -15,11 +15,10 @@ export function runInteractionStateMixinSuite(customConfig) { const cfg = { tagString: null, allowedModelValueTypes: [Array, Object, Number, Boolean, String, Date], - suffix: '', ...customConfig, }; - describe(`InteractionStateMixin ${cfg.suffix ? `(${cfg.suffix})` : ''}`, async () => { + describe(`InteractionStateMixin`, async () => { let tag; before(() => { if (!cfg.tagString) { @@ -174,6 +173,18 @@ export function runInteractionStateMixinSuite(customConfig) { expect(el.prefilled).to.be.true; }); + it('has a method initInteractionState()', async () => { + const el = await fixture(html`<${tag}>`); + el.modelValue = 'Some value'; + expect(el.dirty).to.be.true; + expect(el.touched).to.be.false; + expect(el.prefilled).to.be.false; + el.initInteractionState(); + expect(el.dirty).to.be.false; + expect(el.touched).to.be.false; + expect(el.prefilled).to.be.true; + }); + describe('SubClassers', () => { it('can override the `_leaveEvent`', async () => { const tagLeaveString = defineCE(