mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Stepper): should not display NaN
This commit is contained in:
parent
09fdde8c56
commit
7327a481d1
@ -2,6 +2,7 @@ import { createNamespace, isDef, addUnit } from '../utils';
|
|||||||
import { resetScroll } from '../utils/dom/reset-scroll';
|
import { resetScroll } from '../utils/dom/reset-scroll';
|
||||||
import { preventDefault } from '../utils/dom/event';
|
import { preventDefault } from '../utils/dom/event';
|
||||||
import { formatNumber } from '../utils/format/number';
|
import { formatNumber } from '../utils/format/number';
|
||||||
|
import { isNaN } from '../utils/validate/number';
|
||||||
import { FieldMixin } from '../mixins/field';
|
import { FieldMixin } from '../mixins/field';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('stepper');
|
const [createComponent, bem] = createNamespace('stepper');
|
||||||
@ -153,6 +154,7 @@ export default createComponent({
|
|||||||
|
|
||||||
// format range
|
// format range
|
||||||
value = value === '' ? 0 : +value;
|
value = value === '' ? 0 : +value;
|
||||||
|
value = isNaN(value) ? this.min : value;
|
||||||
value = Math.max(Math.min(this.max, value), this.min);
|
value = Math.max(Math.min(this.max, value), this.min);
|
||||||
|
|
||||||
// format decimal
|
// format decimal
|
||||||
@ -210,7 +212,6 @@ export default createComponent({
|
|||||||
this.$emit('focus', event);
|
this.$emit('focus', event);
|
||||||
|
|
||||||
// readonly not work in lagacy mobile safari
|
// readonly not work in lagacy mobile safari
|
||||||
/* istanbul ignore if */
|
|
||||||
if (this.disableInput && this.$refs.input) {
|
if (this.disableInput && this.$refs.input) {
|
||||||
this.$refs.input.blur();
|
this.$refs.input.blur();
|
||||||
}
|
}
|
||||||
|
@ -157,11 +157,30 @@ test('only allow interger', () => {
|
|||||||
expect(wrapper.emitted('input')[1][0]).toEqual(1);
|
expect(wrapper.emitted('input')[1][0]).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('input invalid value and blur', () => {
|
||||||
|
const wrapper = mount(Stepper, {
|
||||||
|
propsData: {
|
||||||
|
value: '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const input = wrapper.find('input');
|
||||||
|
input.element.value = '.';
|
||||||
|
input.trigger('input');
|
||||||
|
input.trigger('blur');
|
||||||
|
|
||||||
|
expect(wrapper.emitted('input').pop()).toEqual([1]);
|
||||||
|
});
|
||||||
|
|
||||||
test('stepper focus', () => {
|
test('stepper focus', () => {
|
||||||
const wrapper = mount(Stepper);
|
const wrapper = mount(Stepper);
|
||||||
const input = wrapper.find('input');
|
const input = wrapper.find('input');
|
||||||
input.trigger('focus');
|
input.trigger('focus');
|
||||||
expect(wrapper.emitted('focus')).toBeTruthy();
|
expect(wrapper.emitted('focus')).toBeTruthy();
|
||||||
|
|
||||||
|
wrapper.setProps({ disableInput: true });
|
||||||
|
input.trigger('focus');
|
||||||
|
expect(wrapper.emitted('blur')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stepper blur', () => {
|
test('stepper blur', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user