feat(Input/Textarea): allow null value in model (#3415)

This commit is contained in:
Iván Máximiliano, Lo Giudice
2025-03-07 14:17:30 -03:00
committed by GitHub
parent ed7710a890
commit cfe9b2ecf3
4 changed files with 18 additions and 8 deletions

View File

@@ -74,7 +74,7 @@ const props = withDefaults(defineProps<TextareaProps>(), {
defineSlots<TextareaSlots>()
const emits = defineEmits<TextareaEmits>()
const [modelValue, modelModifiers] = defineModel<string | number>()
const [modelValue, modelModifiers] = defineModel<string | number | null>()
const { emitFormFocus, emitFormBlur, emitFormInput, emitFormChange, size, color, id, name, highlight, disabled, ariaAttrs } = useFormField<TextareaProps>(props, { deferInputValidation: true })
@@ -94,15 +94,19 @@ function autoFocus() {
}
// Custom function to handle the v-model properties
function updateInput(value: string) {
function updateInput(value: string | null) {
if (modelModifiers.trim) {
value = value.trim()
value = value?.trim() ?? null
}
if (modelModifiers.number) {
value = looseToNumber(value)
}
if (modelModifiers.nullify) {
value ||= null
}
modelValue.value = value
emitFormInput()
}