mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-05 19:41:42 +08:00
fix(Slider): should update startValue when the slider is clicked (#11904)
This commit is contained in:
parent
b2d49a35d9
commit
457e6a2015
@ -133,6 +133,15 @@ export default defineComponent({
|
||||
return addNumber(min, diff);
|
||||
};
|
||||
|
||||
const updateStartValue = () => {
|
||||
const current = props.modelValue;
|
||||
if (isRange(current)) {
|
||||
startValue = current.map(format) as NumberRange;
|
||||
} else {
|
||||
startValue = format(current);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRangeValue = (value: NumberRange) => {
|
||||
// 设置默认值
|
||||
const left = value[0] ?? Number(props.min);
|
||||
@ -164,6 +173,8 @@ export default defineComponent({
|
||||
return;
|
||||
}
|
||||
|
||||
updateStartValue();
|
||||
|
||||
const { min, reverse, vertical, modelValue } = props;
|
||||
const rect = useRect(root);
|
||||
|
||||
@ -204,12 +215,7 @@ export default defineComponent({
|
||||
|
||||
touch.start(event);
|
||||
current = props.modelValue;
|
||||
|
||||
if (isRange(current)) {
|
||||
startValue = current.map(format) as NumberRange;
|
||||
} else {
|
||||
startValue = format(current);
|
||||
}
|
||||
updateStartValue();
|
||||
|
||||
dragStatus.value = 'start';
|
||||
};
|
||||
|
@ -182,6 +182,8 @@ test('should emit "update:modelValue" event after clicking vertical slider', ()
|
||||
});
|
||||
|
||||
test('should not emit change event when value not changed', async () => {
|
||||
const restoreMock = mockRect();
|
||||
|
||||
const wrapper = mount(Slider, {
|
||||
props: {
|
||||
modelValue: 50,
|
||||
@ -196,8 +198,16 @@ test('should not emit change event when value not changed', async () => {
|
||||
await wrapper.setProps({ modelValue: 100 });
|
||||
trigger(button, 'touchstart');
|
||||
trigger(wrapper, 'click', 100, 0);
|
||||
|
||||
expect(wrapper.emitted('change')).toHaveLength(1);
|
||||
|
||||
trigger(wrapper, 'click', 50, 0);
|
||||
expect(wrapper.emitted('change')).toHaveLength(2);
|
||||
|
||||
await wrapper.setProps({ modelValue: 50 });
|
||||
trigger(wrapper, 'click', 100, 0);
|
||||
expect(wrapper.emitted('change')).toHaveLength(3);
|
||||
|
||||
restoreMock();
|
||||
});
|
||||
|
||||
// https://github.com/vant-ui/vant/issues/8889
|
||||
|
Loading…
x
Reference in New Issue
Block a user