fix(components): [input-number] dynamic precision render value (#21558)

* fix(components): [input-number] dynamic precision render value

* chore: test case
This commit is contained in:
btea
2025-07-31 15:44:12 +08:00
committed by GitHub
parent 822a5796b9
commit 5e402ac252
2 changed files with 26 additions and 0 deletions

View File

@@ -36,6 +36,25 @@ describe('InputNumber.vue', () => {
expect(wrapper.find('p').element.innerText).toBeUndefined()
})
test('dynamic change the precision value should correct re-render', async () => {
const num = ref(123.12)
const precision = ref(1)
const wrapper = mount(() => (
<>
<InputNumber
modelValue={num.value}
placeholder="input number"
precision={precision.value}
/>
</>
))
await nextTick()
expect(wrapper.find('input').element.value).toEqual('123.1')
precision.value = 2
await nextTick()
expect(wrapper.find('input').element.value).toEqual('123.12')
})
test('set modelValue undefined to display placeholder', async () => {
const inputText = ref<number | undefined>(1)
const wrapper = mount(() => (

View File

@@ -358,6 +358,13 @@ watch(
},
{ immediate: true }
)
watch(
() => props.precision,
() => {
data.currentValue = verifyValue(props.modelValue)
}
)
onMounted(() => {
const { min, max, modelValue } = props
const innerInput = input.value?.input as HTMLInputElement