Skip to content

fix(vue): honour v-model.lazy on input components - #31804

Open
AdityaxDeore wants to merge 1 commit into
ionic-team:mainfrom
AdityaxDeore:fix/31761-vue-v-model-lazy
Open

AdityaxDeore wants to merge 1 commit into
ionic-team:mainfrom
AdityaxDeore:fix/31761-vue-v-model-lazy

Conversation

@AdityaxDeore

Copy link
Copy Markdown

Fixes #31761

Problem

v-model.lazy on ion-input, ion-textarea, ion-searchbar, ion-input-otp and ion-range updates the bound value on every keystroke instead of committing on change. The Vue proxies are generated by @stencil/vue-output-target and its defineContainer runtime always emits update:modelValue on the configured model event (ionInput here) — it never reads modelModifiers, so .lazy is silently ignored.

Fix

Hand-written wrappers around the five generated proxies, sharing one helper (packages/vue/src/utils/lazy-model.ts):

  • Default behaviour is unchanged: the inner proxy's update:modelValue (fired on ionInput) is forwarded as before.
  • With modelModifiers.lazy, those updates are dropped and the value commits on ionChange instead, which fires at the same moments as a native change event.
  • The user's own ionChange listener is still called.
  • modelValue is only forwarded to the inner proxy when the parent actually provided it (checked via the vnode props, so v-model bound to undefined still clears the input). Otherwise the proxy falls back to the value prop, so :value without v-model keeps working.

Explicit named exports in packages/vue/src/index.ts take precedence over the generated ones from ./proxies. .trim / .number are out of scope for this issue.

Testing

New regression test packages/vue/test/base/tests/unit/v-model-lazy.spec.ts (vitest + @vue/test-utils, run in the vue3 test app against the locally built @ionic/vue):

  • 5 lazy tests (one per component): no update on ionInput, commit on ionChange
  • Non-lazy control: updates on ionInput without .lazy
  • User @ionChange listener still fires with .lazy
  • :value without v-model still renders

Fail-before on the unfixed build: 6 failed / 2 passed (the lazy tests failed because update:modelValue fired on ionInput; the listener test failed because the model never committed on ionChange). Pass-after: 8/8. Full tests/unit suite in the vue3 test app against the fixed build: 13 files, 81 tests, all passed.

packages/vue typecheck, eslint and prettier are clean; core and packages/vue builds pass.

Disclosure: AI coding assistance was used in preparing this change.

The generated Vue proxies always emit update:modelValue on ionInput and
never read modelModifiers, so v-model.lazy updated the bound value on every
keystroke instead of committing on change.

Wrap the five input proxies (ion-input, ion-textarea, ion-searchbar,
ion-input-otp, ion-range) in a shared withLazyModel helper: default
behaviour is unchanged, and with .lazy the model commits on ionChange
instead, while the user's own ionChange listener still fires. modelValue is
only forwarded when the parent provided it, so :value without v-model and
v-model bound to undefined keep working.

Regression test: packages/vue/test/base/tests/unit/v-model-lazy.spec.ts
(8 tests: 5 lazy commits, non-lazy control, user ionChange listener,
:value without v-model). Fail-before on the unfixed build: 6 failed /
2 passed; pass-after: 8/8. Full vue3 unit suite: 13 files, 81 tests, all
passed. Typecheck, eslint and prettier clean.

Fixes ionic-team#31761
@AdityaxDeore
AdityaxDeore requested a review from a team as a code owner November 23, 2026 08:15
@AdityaxDeore
AdityaxDeore requested a review from thetaPC November 23, 2026 08:15
@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

@AdityaxDeore is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the package: vue @ionic/vue package label Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: vue @ionic/vue package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: vue: ion-input ignores the v-model.lazy modifier

1 participant