From 1388dd939a4db5bf1738dcabf5a309eeda8e6566 Mon Sep 17 00:00:00 2001 From: inottn Date: Sun, 13 Oct 2024 16:00:58 +0800 Subject: [PATCH] fix(Field): should not adjust value when the min or max props are not set (#13150) --- packages/vant/src/field/Field.tsx | 6 +++++- packages/vant/src/field/test/index.spec.js | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/vant/src/field/Field.tsx b/packages/vant/src/field/Field.tsx index 96dab6e61..4511df21a 100644 --- a/packages/vant/src/field/Field.tsx +++ b/packages/vant/src/field/Field.tsx @@ -334,7 +334,11 @@ export default defineComponent({ const isNumber = props.type === 'number'; value = formatNumber(value, isNumber, isNumber); - if (trigger === 'onBlur' && value !== '') { + if ( + trigger === 'onBlur' && + value !== '' && + (props.min !== undefined || props.max !== undefined) + ) { const adjustedValue = clamp( +value, props.min ?? -Infinity, diff --git a/packages/vant/src/field/test/index.spec.js b/packages/vant/src/field/test/index.spec.js index 5d5278639..911bd7b6b 100644 --- a/packages/vant/src/field/test/index.spec.js +++ b/packages/vant/src/field/test/index.spec.js @@ -59,9 +59,9 @@ test('should format input value when type is number', () => { const input = wrapper.find('input'); - input.element.value = '1'; + input.element.value = '01'; input.trigger('input'); - expect(wrapper.emitted('update:modelValue')[0][0]).toEqual('1'); + expect(wrapper.emitted('update:modelValue')[0][0]).toEqual('01'); input.element.value = '1.2.'; input.trigger('input');