bug: vue: ion-input ignores the v-model.lazy modifier
Prerequisites
- [x] I have read the Contributing Guidelines.
- [x] I agree to follow the Code of Conduct.
- [x] I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
v9.x
Current Behavior
Ion-input doesn't appear to support Vue's lazy modifier on v-model: https://vuejs.org/guide/essentials/forms.html#modifiers The associated ref still updates on every keystroke, rather than on the change event.
Expected Behavior
With v-model.lazy, the connected ref should only update when the input is blurred.
Steps to Reproduce
- Go to: https://stackblitz.com/edit/duayqrjj?file=src%2Fcomponents%2FExample.vue Note
v-model.lazyon both inputs. - Enter any text in the ion-input. Note that the item underneath updates on every keystroke.
- Enter any text in the vanilla input. Note that the item underneath only updates when the input is blurred.
Code Reproduction URL
https://stackblitz.com/edit/duayqrjj?file=src%2Fcomponents%2FExample.vue
Ionic Info
N/A (see stackblitz)
Additional Information
This can be worked around by keeping the ref in sync manually:
<ion-input :value="inputValue" @ionChange="e => inputValue = e.target.value"></ion-input>
Thanks for the report.
Verified on 9.0.12. For components, Vue applies the .trim and .number modifiers itself but leaves .lazy for the component to handle. The Vue wrapper for ion-input ignores it and always updates the bound value on ionInput, which fires on every keystroke. The same happens on ion-textarea, ion-searchbar, ion-input-otp and ion-range.
The workaround in your report works, also verified on 9.0.12. ionChange fires at the same moments as a native change event, on Enter or on blur after an edit:
<template>
<ion-input label="Name" :value="name" @ionChange="name = $event.target.value"></ion-input>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { IonInput } from '@ionic/vue';
const name = ref('');
</script>
Tracked as a bug in @ionic/vue.