Skip to content

Commit

Permalink
fix(Field): should not modify the value if it's within the min/max
Browse files Browse the repository at this point in the history
Co-authored-by: dgmpk <[email protected]>
  • Loading branch information
inottn and dgmpk committed Feb 9, 2025
1 parent 6f507b9 commit 3d5556c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/vant/src/field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ export default defineComponent({
props.min ?? -Infinity,
props.max ?? Infinity,
);
value = adjustedValue.toString();

if (+value !== adjustedValue) {
value = adjustedValue.toString();
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions packages/vant/src/field/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ test('should limit input value based on min and max props', async () => {
expect(wrapper.emitted('update:modelValue')[2][0]).toEqual('5');
});

test('should not modify the value if it is within the min/max', async () => {
const wrapper = mount(Field, {
props: {
type: 'number',
min: 2,
max: 10,
modelValue: '',
},
});

const input = wrapper.find('input');

await wrapper.setProps({ modelValue: '2.00' });
await input.trigger('blur');
expect(wrapper.emitted('update:modelValue')).toBeFalsy();
});

test('should render textarea when type is textarea', async () => {
const wrapper = mount(Field, {
props: {
Expand Down

0 comments on commit 3d5556c

Please sign in to comment.