mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 10:20:19 +08:00
fix(Stepper): should format value when max、min changed (#5257)
This commit is contained in:
parent
c9898d6bec
commit
d19f676953
@ -114,6 +114,11 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
max: 'check',
|
||||||
|
min: 'check',
|
||||||
|
integer: 'check',
|
||||||
|
decimalLength: 'check',
|
||||||
|
|
||||||
currentValue(val) {
|
currentValue(val) {
|
||||||
this.$emit('input', val);
|
this.$emit('input', val);
|
||||||
this.$emit('change', val, { name: this.name });
|
this.$emit('change', val, { name: this.name });
|
||||||
@ -121,6 +126,13 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
check() {
|
||||||
|
const val = this.format(this.currentValue);
|
||||||
|
if (!equal(val, this.currentValue)) {
|
||||||
|
this.currentValue = val;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// filter illegal characters
|
// filter illegal characters
|
||||||
filter(value) {
|
filter(value) {
|
||||||
value = String(value).replace(/[^0-9.-]/g, '');
|
value = String(value).replace(/[^0-9.-]/g, '');
|
||||||
|
@ -271,3 +271,61 @@ test('name prop', () => {
|
|||||||
plus.trigger('click');
|
plus.trigger('click');
|
||||||
expect(wrapper.emitted('change')[1][1]).toEqual({ name: 'name' });
|
expect(wrapper.emitted('change')[1][1]).toEqual({ name: 'name' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('change min and max', async () => {
|
||||||
|
const wrapper = mount(Stepper, {
|
||||||
|
propsData: {
|
||||||
|
value: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.setProps({
|
||||||
|
min: 10,
|
||||||
|
});
|
||||||
|
|
||||||
|
await later();
|
||||||
|
|
||||||
|
expect(wrapper.emitted('input')[0][0]).toEqual(10);
|
||||||
|
|
||||||
|
wrapper.setProps({
|
||||||
|
min: 3,
|
||||||
|
max: 8,
|
||||||
|
});
|
||||||
|
|
||||||
|
await later();
|
||||||
|
|
||||||
|
expect(wrapper.emitted('input')[1][0]).toEqual(8);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('change decimal-length', async () => {
|
||||||
|
const wrapper = mount(Stepper, {
|
||||||
|
propsData: {
|
||||||
|
value: 1.33
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.setProps({
|
||||||
|
decimalLength: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
await later();
|
||||||
|
|
||||||
|
expect(wrapper.emitted('input')[0][0]).toEqual('1.3');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('change integer', async () => {
|
||||||
|
const wrapper = mount(Stepper, {
|
||||||
|
propsData: {
|
||||||
|
value: 1.33
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.setProps({
|
||||||
|
integer: true
|
||||||
|
});
|
||||||
|
|
||||||
|
await later();
|
||||||
|
|
||||||
|
expect(wrapper.emitted('input')[0][0]).toEqual(1);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user