mirror of https://github.com/ElemeFE/element
input-number: fix user input parsing (#9166)
parent
837354df3b
commit
15d528c768
|
@ -162,7 +162,6 @@ Use attribute `size` to set additional sizes with `medium`, `small` or `mini`.
|
||||||
|size | size of the component | string | large/small| — |
|
|size | size of the component | string | large/small| — |
|
||||||
|disabled| whether the component is disabled | boolean | — | false |
|
|disabled| whether the component is disabled | boolean | — | false |
|
||||||
|controls| whether to enable the control buttons | boolean | — | true |
|
|controls| whether to enable the control buttons | boolean | — | true |
|
||||||
|debounce| debounce delay when typing, in milliseconds | number | — | 300 |
|
|
||||||
|controls-position | position of the control buttons | string | right | - |
|
|controls-position | position of the control buttons | string | right | - |
|
||||||
|name | same as `name` in native input | string | — | — |
|
|name | same as `name` in native input | string | — | — |
|
||||||
|label | label text | string | — | — |
|
|label | label text | string | — | — |
|
||||||
|
|
|
@ -163,7 +163,6 @@ Utilice el atributo `size` para establecer tamaños adicionales con `medium`, `s
|
||||||
| size | tamaño del componente | string | large/small | — |
|
| size | tamaño del componente | string | large/small | — |
|
||||||
| disabled | si el componente esta deshabilitado | boolean | — | false |
|
| disabled | si el componente esta deshabilitado | boolean | — | false |
|
||||||
| controls | si se activan los botones de control | boolean | — | true |
|
| controls | si se activan los botones de control | boolean | — | true |
|
||||||
| debounce | retardo de rebote al escribir, en milisegundos | number | — | 300 |
|
|
||||||
| controls-position | posición de los botones de control | string | right | - |
|
| controls-position | posición de los botones de control | string | right | - |
|
||||||
| name | lo mismo que `name` en un input nativo | string | — | — |
|
| name | lo mismo que `name` en un input nativo | string | — | — |
|
||||||
| label | texto de la etiqueta | string | — | — |
|
| label | texto de la etiqueta | string | — | — |
|
||||||
|
|
|
@ -159,7 +159,6 @@
|
||||||
| size | 计数器尺寸 | string | large, small | — |
|
| size | 计数器尺寸 | string | large, small | — |
|
||||||
| disabled | 是否禁用计数器 | boolean | — | false |
|
| disabled | 是否禁用计数器 | boolean | — | false |
|
||||||
| controls | 是否使用控制按钮 | boolean | — | true |
|
| controls | 是否使用控制按钮 | boolean | — | true |
|
||||||
| debounce | 输入时的去抖延迟,毫秒 | number | — | 300 |
|
|
||||||
| controls-position | 控制按钮位置 | string | right | - |
|
| controls-position | 控制按钮位置 | string | right | - |
|
||||||
| name | 原生属性 | string | — | — |
|
| name | 原生属性 | string | — | — |
|
||||||
| label | 输入框关联的label文字 | string | — | — |
|
| label | 输入框关联的label文字 | string | — | — |
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
@keydown.down.native.prevent="decrease"
|
@keydown.down.native.prevent="decrease"
|
||||||
@blur="handleBlur"
|
@blur="handleBlur"
|
||||||
@focus="handleFocus"
|
@focus="handleFocus"
|
||||||
@input="debounceHandleInput"
|
@change="handleInputChange"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:size="inputNumberSize"
|
:size="inputNumberSize"
|
||||||
:max="max"
|
:max="max"
|
||||||
|
@ -47,13 +47,12 @@
|
||||||
</template>
|
</template>
|
||||||
<template slot="append" v-if="$slots.append">
|
<template slot="append" v-if="$slots.append">
|
||||||
<slot name="append"></slot>
|
<slot name="append"></slot>
|
||||||
</template>
|
</template>
|
||||||
</el-input>
|
</el-input>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import ElInput from 'element-ui/packages/input';
|
import ElInput from 'element-ui/packages/input';
|
||||||
import debounce from 'throttle-debounce/debounce';
|
|
||||||
import Focus from 'element-ui/src/mixins/focus';
|
import Focus from 'element-ui/src/mixins/focus';
|
||||||
import RepeatClick from 'element-ui/src/directives/repeat-click';
|
import RepeatClick from 'element-ui/src/directives/repeat-click';
|
||||||
|
|
||||||
|
@ -97,10 +96,6 @@
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
debounce: {
|
|
||||||
type: Number,
|
|
||||||
default: 300
|
|
||||||
},
|
|
||||||
name: String,
|
name: String,
|
||||||
label: String
|
label: String
|
||||||
},
|
},
|
||||||
|
@ -204,32 +199,13 @@
|
||||||
this.$emit('input', newVal);
|
this.$emit('input', newVal);
|
||||||
this.currentValue = newVal;
|
this.currentValue = newVal;
|
||||||
},
|
},
|
||||||
handleInput(value) {
|
handleInputChange(value) {
|
||||||
if (value === '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value.indexOf('.') === (value.length - 1)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value.indexOf('-') === (value.length - 1)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const newVal = Number(value);
|
const newVal = Number(value);
|
||||||
if (!isNaN(newVal)) {
|
if (!isNaN(newVal)) {
|
||||||
this.setCurrentValue(newVal);
|
this.setCurrentValue(newVal);
|
||||||
} else {
|
|
||||||
this.$refs.input.setCurrentValue(this.currentValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
this.debounceHandleInput = debounce(this.debounce, value => {
|
|
||||||
this.handleInput(value);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
mounted() {
|
mounted() {
|
||||||
let innerInput = this.$refs.input.$refs.input;
|
let innerInput = this.$refs.input.$refs.input;
|
||||||
innerInput.setAttribute('role', 'spinbutton');
|
innerInput.setAttribute('role', 'spinbutton');
|
||||||
|
|
|
@ -285,7 +285,7 @@ describe('InputNumber', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emit on input', done => {
|
it('emit on input', done => {
|
||||||
vm.$refs.compo.handleInput('3');
|
vm.$refs.compo.handleInputChange('3');
|
||||||
setTimeout(_ => {
|
setTimeout(_ => {
|
||||||
expect(spy.calledOnce).to.be.true;
|
expect(spy.calledOnce).to.be.true;
|
||||||
expect(spy.args[0][0]).to.equal(3);
|
expect(spy.args[0][0]).to.equal(3);
|
||||||
|
|
Loading…
Reference in New Issue