瀏覽代碼

input-number: fix user input parsing (#9166)

Jiewei Qian 7 年之前
父節點
當前提交
15d528c768

+ 0 - 1
examples/docs/en-US/input-number.md

@@ -162,7 +162,6 @@ Use attribute `size` to set additional sizes with `medium`, `small` or `mini`.
 |size | size of the component | string | large/small| — |
 |disabled| whether the component is disabled | boolean | — | false |
 |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 | - |
 |name | same as `name` in native input | string | — | — |
 |label | label text | string | — | — |

+ 0 - 1
examples/docs/es/input-number.md

@@ -163,7 +163,6 @@ Utilice el atributo `size` para establecer tamaños adicionales con `medium`, `s
 | size              | tamaño del componente                    | string  | large/small       | —           |
 | disabled          | si el componente esta deshabilitado      | boolean | —                 | false       |
 | 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             | -           |
 | name              | lo mismo que `name` en un input nativo   | string  | —                 | —           |
 | label             | texto de la etiqueta                     | string  | —                 | —           |

+ 0 - 1
examples/docs/zh-CN/input-number.md

@@ -159,7 +159,6 @@
 | size     | 计数器尺寸           | string   | large, small | — |
 | disabled | 是否禁用计数器        | boolean | — | false |
 | controls | 是否使用控制按钮        | boolean | — | true |
-| debounce | 输入时的去抖延迟,毫秒 | number | — | 300 |
 | controls-position | 控制按钮位置 | string | right | - |
 | name | 原生属性 | string | — | — |
 | label | 输入框关联的label文字 | string | — | — |

+ 3 - 27
packages/input-number/src/input-number.vue

@@ -33,7 +33,7 @@
       @keydown.down.native.prevent="decrease"
       @blur="handleBlur"
       @focus="handleFocus"
-      @input="debounceHandleInput"
+      @change="handleInputChange"
       :disabled="disabled"
       :size="inputNumberSize"
       :max="max"
@@ -47,13 +47,12 @@
       </template>
       <template slot="append" v-if="$slots.append">
         <slot name="append"></slot>
-      </template> 
+      </template>
     </el-input>
   </div>
 </template>
 <script>
   import ElInput from 'element-ui/packages/input';
-  import debounce from 'throttle-debounce/debounce';
   import Focus from 'element-ui/src/mixins/focus';
   import RepeatClick from 'element-ui/src/directives/repeat-click';
 
@@ -97,10 +96,6 @@
         type: String,
         default: ''
       },
-      debounce: {
-        type: Number,
-        default: 300
-      },
       name: String,
       label: String
     },
@@ -204,32 +199,13 @@
         this.$emit('input', newVal);
         this.currentValue = newVal;
       },
-      handleInput(value) {
-        if (value === '') {
-          return;
-        }
-
-        if (value.indexOf('.') === (value.length - 1)) {
-          return;
-        }
-
-        if (value.indexOf('-') === (value.length - 1)) {
-          return;
-        }
-
+      handleInputChange(value) {
         const newVal = Number(value);
         if (!isNaN(newVal)) {
           this.setCurrentValue(newVal);
-        } else {
-          this.$refs.input.setCurrentValue(this.currentValue);
         }
       }
     },
-    created() {
-      this.debounceHandleInput = debounce(this.debounce, value => {
-        this.handleInput(value);
-      });
-    },
     mounted() {
       let innerInput = this.$refs.input.$refs.input;
       innerInput.setAttribute('role', 'spinbutton');

+ 1 - 1
test/unit/specs/input-number.spec.js

@@ -285,7 +285,7 @@ describe('InputNumber', () => {
     });
 
     it('emit on input', done => {
-      vm.$refs.compo.handleInput('3');
+      vm.$refs.compo.handleInputChange('3');
       setTimeout(_ => {
         expect(spy.calledOnce).to.be.true;
         expect(spy.args[0][0]).to.equal(3);