|
123 | 123 | onUpdated, |
124 | 124 | getCurrentInstance, |
125 | 125 | ComponentInternalInstance, |
126 | | - toRefs |
| 126 | + toRefs, ref |
127 | 127 | } from 'vue' |
128 | 128 | import Migrating from '@/mixins/migrating' |
129 | 129 | // @ts-ignore |
|
212 | 212 | attrs, |
213 | 213 | slots |
214 | 214 | }) |
| 215 | + const inputValue = ref(props.modelValue) |
215 | 216 | const emitter: Emitter = mitt() |
216 | 217 | const elForm = inject('elForm', {}) as elFormInject |
217 | 218 | const elFormItem = inject('elFormItem', {}) as elFormItemInject |
|
282 | 283 | return isWordLimitVisible && |
283 | 284 | (textLength > upperLimit) |
284 | 285 | }) |
285 | | -
|
| 286 | + const finalValue = computed(() => { |
| 287 | + const isNumber = !!(attrs.modelModifiers as anyObject)?.number |
| 288 | + const value = parseFloat(String(inputValue.value)) |
| 289 | + return isNumber ? isNaN(value) ? '' : value : inputValue.value |
| 290 | + }) |
286 | 291 | watch(() => props.modelValue, (val) => { |
287 | 292 | nextTick(resizeTextarea) |
288 | 293 | if (props.validateEvent) { |
|
367 | 372 | handleInput(event) |
368 | 373 | } |
369 | 374 | } |
| 375 | + watch(() => finalValue.value, (value: String | Number) => { |
| 376 | + emit('update:modelValue', value) |
| 377 | + emit('input', value) |
| 378 | + }) |
370 | 379 | const handleInput = (event: Event) => { |
371 | 380 | // should not emit input during composition |
372 | 381 | // see: https://github.com/ElemeFE/element/issues/10516 |
|
376 | 385 | // hack for https://github.com/ElemeFE/element/issues/8548 |
377 | 386 | // should remove the following line when we don't support IE |
378 | 387 | if (value === nativeInputValue.value) return |
379 | | - const isNumber = !!(attrs.modelModifiers as anyObject)?.number |
380 | | - const finalValue = isNumber ? isNaN(parseFloat(value)) ? '' : parseFloat(value) : value |
381 | | - emit('update:modelValue', finalValue) |
382 | | - emit('input', finalValue) |
| 388 | + inputValue.value = value |
383 | 389 | // ensure native input value is controlled |
384 | 390 | // see: https://github.com/ElemeFE/element/issues/12850 |
385 | 391 | nextTick(setNativeInputValue) |
386 | 392 | } |
387 | 393 | const handleChange = (event: Event) => { |
388 | | - emit('change', (event.target as HTMLInputElement)?.value) |
| 394 | + emit('change', finalValue.value) |
389 | 395 | } |
390 | 396 | const calcIconOffset = (place: 'suffix' | 'prefix') => { |
391 | 397 | const $el = instance.vnode.el |
|
420 | 426 | setNativeInputValue() |
421 | 427 | emit('input', '') |
422 | 428 | emit('change', '') |
| 429 | + console.log('clear') |
423 | 430 | emit('update:modelValue', '') |
424 | 431 | emit('clear') |
425 | 432 | }) |
|
492 | 499 | handlePasswordVisible, |
493 | 500 | getInput, |
494 | 501 | getSuffixVisible |
495 | | -
|
496 | 502 | } |
497 | 503 | }, |
498 | 504 |
|
|
0 commit comments