fix(components): [input] fix formatter and parse problem (#12622)

* fix(components): [input] fix formatter and parse problem

closed #12613

* fix(components): [input] fix input value problem

* fix(components): [input] update return value for input event emit

* test(components): [input] add test for formatter and parser
This commit is contained in:
wzc520pyfm 2023-06-04 13:51:44 +08:00 committed by GitHub
parent bac64b4801
commit 03e2a15411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -266,8 +266,12 @@ describe('Input.vue', () => {
))
const vm = wrapper.vm
expect(vm.$el.querySelector('input').value).toEqual('10000')
const event = new Event('input', { bubbles: true })
expect(vm.$el.querySelector('input').value).toEqual('10,000')
expect(vm.$el.querySelector('input').value).not.toEqual('1000')
vm.$el.querySelector('input').value = '1,000,000'
vm.$el.querySelector('input').dispatchEvent(event)
expect(val.value).toEqual('1000000')
})
describe('Input Methods', () => {

View File

@ -371,8 +371,11 @@ const onceInitSizeTextarea = createOnceInitResize(resizeTextarea)
const setNativeInputValue = () => {
const input = _ref.value
if (!input || input.value === nativeInputValue.value) return
input.value = nativeInputValue.value
const formatterValue = props.formatter
? props.formatter(nativeInputValue.value)
: nativeInputValue.value
if (!input || input.value === formatterValue) return
input.value = formatterValue
}
const handleInput = async (event: Event) => {
@ -382,7 +385,6 @@ const handleInput = async (event: Event) => {
if (props.formatter) {
value = props.parser ? props.parser(value) : value
value = props.formatter(value)
}
// should not emit input during composition