mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-05 12:48:04 +08:00
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:
parent
bac64b4801
commit
03e2a15411
@ -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', () => {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user