Skip to content

Commit c7024d4

Browse files
inottndgmpkchenjiahan
authored
test(Field): should not modify the value if it's within the min/max (#13343)
Co-authored-by: dgmpk <465316497@qq.com> Co-authored-by: neverland <jait.chen@foxmail.com>
1 parent 507e397 commit c7024d4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/vant/src/field/Field.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ export default defineComponent({
346346
props.min ?? -Infinity,
347347
props.max ?? Infinity,
348348
);
349+
349350
if (+value !== adjustedValue) {
350351
value = adjustedValue.toString();
351352
}

packages/vant/src/field/test/index.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,23 @@ test('should limit input value based on min and max props', async () => {
123123
expect(wrapper.emitted('update:modelValue')[2][0]).toEqual('5');
124124
});
125125

126+
test('should not modify the value if it is within the min/max', async () => {
127+
const wrapper = mount(Field, {
128+
props: {
129+
type: 'number',
130+
min: 2,
131+
max: 10,
132+
modelValue: '',
133+
},
134+
});
135+
136+
const input = wrapper.find('input');
137+
138+
await wrapper.setProps({ modelValue: '2.00' });
139+
await input.trigger('blur');
140+
expect(wrapper.emitted('update:modelValue')).toBeFalsy();
141+
});
142+
126143
test('should render textarea when type is textarea', async () => {
127144
const wrapper = mount(Field, {
128145
props: {

0 commit comments

Comments
 (0)