Skip to content

Commit

Permalink
fix(Field): should not adjust value when the min or max props are not…
Browse files Browse the repository at this point in the history
… set
  • Loading branch information
inottn committed Oct 3, 2024
1 parent dcc008a commit c72ca19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/vant/src/field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/vant/src/field/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit c72ca19

Please sign in to comment.