mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Stepper): should limit decimal length when input (#4747)
This commit is contained in:
parent
a65bd84e0a
commit
acc972a203
@ -149,7 +149,13 @@ export default createComponent({
|
||||
return;
|
||||
}
|
||||
|
||||
const formatted = this.filter(value);
|
||||
let formatted = this.filter(value);
|
||||
|
||||
// limit max decimal length
|
||||
if (isDef(this.decimalLength) && formatted.indexOf('.') !== -1) {
|
||||
const pair = formatted.split('.');
|
||||
formatted = `${pair[0]}.${pair[1].slice(0, this.decimalLength)}`;
|
||||
}
|
||||
|
||||
if (!equal(value, formatted)) {
|
||||
event.target.value = formatted;
|
||||
|
@ -213,3 +213,19 @@ test('decimal-length prop', () => {
|
||||
plus.trigger('click');
|
||||
expect(wrapper.emitted('input')[1][0]).toEqual('1.20');
|
||||
});
|
||||
|
||||
test('should limit decimal-length when input', () => {
|
||||
const wrapper = mount(Stepper, {
|
||||
propsData: {
|
||||
value: 1,
|
||||
step: 0.2,
|
||||
decimalLength: 1
|
||||
}
|
||||
});
|
||||
|
||||
const input = wrapper.find('input');
|
||||
input.element.value = '1.25';
|
||||
input.trigger('input');
|
||||
|
||||
expect(input.element.value).toEqual('1.2');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user