Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
30af04b
fix(Picker): fix bug the content of the popup window is not consiste…
lllomh Sep 18, 2023
37fc0b8
fix(Picker): Fix the issue that scroll wheel selection list is not su…
lllomh Sep 20, 2023
72c750b
fix(Picker): Rollback of new commits last one
lllomh Sep 20, 2023
f7685da
Merge branch 'main' into main
lllomh Sep 21, 2023
c5b0ba9
Merge branch 'youzan:main' into main
lllomh Sep 27, 2023
3430626
Merge branch 'youzan:main' into main
lllomh Sep 17, 2025
be2e46d
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
c7fe1a6
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
13248f7
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
42d9458
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
5d85c3b
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
8137a85
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
5a48f52
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
d24b1e7
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
e37c8fe
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
91259b9
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
a3774da
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
288cd25
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
b5ee53a
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
06b35df
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
22ceb87
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
a7e2f52
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
bc40733
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
6bbbb14
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
08064d3
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
cb5f579
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 17, 2025
736f8b4
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 18, 2025
8810099
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 18, 2025
6cfc45d
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 18, 2025
b5a0091
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 18, 2025
5ef1075
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 18, 2025
0547793
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 18, 2025
3a39f04
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 18, 2025
ee47f30
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 18, 2025
6953c40
fix(Button): When the step value of the Slider component is relativel…
lllomh Sep 18, 2025
5dd6def
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
ef5c686
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
38ce3e7
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
fd9c90d
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
b7648e0
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
a03d1b3
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
9be4cbd
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
ca1e404
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
37f1d8a
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
aeadef6
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
f9a1d0d
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
f8c6668
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
835676e
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
e996104
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
9282a87
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
728aae9
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
e8c4b50
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
aa4f540
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
46318fe
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
7f7ce3f
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
a5e8351
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
a90cace
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 21, 2025
572efca
Merge branch 'main' into main
lllomh Sep 21, 2025
d0cafc7
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 22, 2025
8de91ac
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 22, 2025
c039ba7
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 22, 2025
ac685ee
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 22, 2025
9dcc149
fix(Slider): When the step value of the Slider component is relativel…
lllomh Sep 22, 2025
ffa9237
Merge branch 'youzan:main' into main
lllomh Feb 18, 2026
a5f73ef
fix(Field): sync input value when dynamically toggling input slot
lllomh Feb 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/vant/src/field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,17 @@ export default defineComponent({
},
);

// Sync value when input element is recreated (e.g., when toggling custom input slot)
// https://github.com/youzan/vant/issues/13769
watch(
() => inputRef.value,
(input) => {
if (input && input.value !== getModelValue()) {
input.value = getModelValue();
}
},
);
Comment on lines +689 to +698

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The new watcher correctly addresses the issue of syncing the input value when the input element is recreated due to dynamic slot toggling. This is a good solution to ensure data consistency.


onMounted(() => {
updateValue(getModelValue(), props.formatTrigger);
nextTick(adjustTextareaSize);
Expand Down
41 changes: 41 additions & 0 deletions packages/vant/src/field/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,44 @@ test('should limit maxlength correctly when pasting multiple emojis', async () =
expect(wrapper.emitted('update:modelValue')[0][0]).toEqual('1😀😀😀');
expect(input.element.value).toEqual('1😀😀😀');
});

test('should sync value when dynamically toggling input slot', async () => {
const wrapper = mount({
data() {
return {
useSlot: false,
modelValue: 'hello',
};
},
render() {
return (
<Field
v-model={this.modelValue}
v-slots={{
input: this.useSlot ? () => 'Custom Input' : undefined,
}}
/>
);
},
});

let input = wrapper.find('input');
expect(input.element.value).toEqual('hello');

// Toggle to use custom input slot
await wrapper.vm.$data.useSlot = true;
await wrapper.vm.$nextTick();
expect(wrapper.find('.van-field__control').text()).toContain('Custom Input');

// Update model value while slot is active
await wrapper.vm.$data.modelValue = 'world';
await wrapper.vm.$nextTick();

// Toggle back to native input
await wrapper.vm.$data.useSlot = false;
await wrapper.vm.$nextTick();

// The native input should have the updated value
input = wrapper.find('input');
expect(input.element.value).toEqual('world');
});
Comment on lines +667 to +706

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This new test case effectively covers the scenario of dynamically toggling the input slot and verifies that the value is correctly synced. It's well-structured and clearly demonstrates the bug fix.

12 changes: 11 additions & 1 deletion packages/vant/src/slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,18 @@ export default defineComponent({
const step = +props.step;

value = clamp(value, min, max);

const diff = Math.round((value - min) / step) * step;
return addNumber(min, diff);
const steppedValue = addNumber(min, diff);

if (steppedValue > max) {
const prevSteppedValue = addNumber(min, diff - step);
const distanceToMax = Math.abs(value - max);
const distanceToPrev = Math.abs(value - prevSteppedValue);

return distanceToMax <= distanceToPrev ? max : prevSteppedValue;
}
return steppedValue;
Comment on lines +132 to +143

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for handling steppedValue > max is a good addition to ensure the slider value correctly snaps to max or the previous stepped value when the calculated stepped value exceeds the maximum. This improves the precision and reliability of the slider's value calculation.

};

const updateStartValue = () => {
Expand Down
28 changes: 28 additions & 0 deletions packages/vant/src/slider/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,31 @@ test('should update modelValue correctly after clicking the reversed vertical sl
trigger(wrapper, 'click', 0, 100);
expect(wrapper.emitted('update:modelValue')!.pop()).toEqual([0]);
});

//https://github.com/youzan/vant/issues/13625
test('should return max when distanceToMax <= distanceToPrev', () => {
const wrapper = mount(Slider, {
props: { min: 0, max: 50, step: 60, modelValue: 45 },
});

const emitted = wrapper.emitted('update:modelValue');
if (emitted && emitted.length > 0) {
const result = emitted[emitted.length - 1][0] as number;
expect(result).toBe(50); // Should return max
}
Comment on lines +378 to +388

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test case specifically targets the edge scenario where distanceToMax <= distanceToPrev, ensuring the slider correctly returns the max value. This is a good addition for robustness.

});

test('should enter steppedValue > max branch', () => {
const wrapper = mount(Slider, {
props: { min: 0, max: 12, step: 20, modelValue: 0 },
});

wrapper.setProps({ modelValue: 11 });

const emitted = wrapper.emitted('update:modelValue');
if (emitted && emitted.length > 0) {
const result = emitted[emitted.length - 1][0] as number;
expect(result).toBeGreaterThanOrEqual(0);
expect(result).toBeLessThanOrEqual(12);
}
Comment on lines +391 to +403

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test case verifies the behavior when steppedValue exceeds max, ensuring the value is correctly clamped within the min and max range. This helps confirm the new logic in format function works as expected.

});
Loading