feat(Stepper): should limit decimal length when input (#4747)

This commit is contained in:
neverland 2019-10-16 16:37:28 +08:00 committed by GitHub
parent a65bd84e0a
commit acc972a203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -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;

View File

@ -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');
});