Input: simplify el-input implementation (#13471)

* input: simplify internal implementation

remove currentValue, strictly follow one-way data flow
hack for MSIE input event when placeholder is set
remove isKorean hack (#11665, #10648)

* input-number: fix for new el-input

* test: input, fix vue warning

* date-time-range: fix for new el-input

* pagination: fix for new el-input, simplify internals

* input: fix input event on compositionend

* input-number: fix for new el-input

* input-number: nuke userInput on change
This commit is contained in:
Jiewei Qian
2018-11-26 18:05:46 +11:00
committed by hetech
parent dd4a496940
commit e2c5573c1f
7 changed files with 132 additions and 133 deletions

View File

@@ -215,56 +215,36 @@ export default {
Jumper: {
mixins: [Locale],
components: { ElInput },
data() {
return {
oldValue: null
userInput: null
};
},
components: { ElInput },
watch: {
'$parent.internalPageSize'() {
this.$nextTick(() => {
this.$refs.input.$el.querySelector('input').value = this.$parent.internalCurrentPage;
});
'$parent.internalCurrentPage'() {
this.userInput = null;
}
},
methods: {
handleFocus(event) {
this.oldValue = event.target.value;
},
handleBlur({ target }) {
this.resetValueIfNeed(target.value);
this.reassignMaxValue(target.value);
},
handleKeyup({ keyCode, target }) {
if (keyCode === 13 && this.oldValue && target.value !== this.oldValue) {
// Chrome, Safari, Firefox triggers change event on Enter
// Hack for IE: https://github.com/ElemeFE/element/issues/11710
// Drop this method when we no longer supports IE
if (keyCode === 13) {
this.handleChange(target.value);
}
},
handleInput(value) {
this.userInput = value;
},
handleChange(value) {
this.$parent.internalCurrentPage = this.$parent.getValidCurrentPage(value);
this.$parent.emitChange();
this.oldValue = null;
this.resetValueIfNeed(value);
},
resetValueIfNeed(value) {
const num = parseInt(value, 10);
if (!isNaN(num)) {
if (num < 1) {
this.$refs.input.setCurrentValue(1);
} else {
this.reassignMaxValue(value);
}
}
},
reassignMaxValue(value) {
const { internalPageCount } = this.$parent;
if (+value > internalPageCount) {
this.$refs.input.setCurrentValue(internalPageCount || 1);
}
this.userInput = null;
}
},
@@ -276,15 +256,12 @@ export default {
class="el-pagination__editor is-in-pagination"
min={ 1 }
max={ this.$parent.internalPageCount }
value={ this.$parent.internalCurrentPage }
domPropsValue={ this.$parent.internalCurrentPage }
value={ this.userInput !== null ? this.userInput : this.$parent.internalCurrentPage }
type="number"
ref="input"
disabled={ this.$parent.disabled }
nativeOnKeyup={ this.handleKeyup }
onChange={ this.handleChange }
onFocus={ this.handleFocus }
onBlur={ this.handleBlur }/>
onInput={ this.handleInput }
onChange={ this.handleChange }/>
{ this.t('el.pagination.pageClassifier') }
</span>
);
@@ -380,7 +357,7 @@ export default {
currentPage: {
immediate: true,
handler(val) {
this.internalCurrentPage = val;
this.internalCurrentPage = this.getValidCurrentPage(val);
}
},
@@ -393,24 +370,8 @@ export default {
internalCurrentPage: {
immediate: true,
handler(newVal, oldVal) {
newVal = parseInt(newVal, 10);
/* istanbul ignore if */
if (isNaN(newVal)) {
newVal = oldVal || 1;
} else {
newVal = this.getValidCurrentPage(newVal);
}
if (newVal !== undefined) {
this.internalCurrentPage = newVal;
if (oldVal !== newVal) {
this.$emit('update:currentPage', newVal);
}
} else {
this.$emit('update:currentPage', newVal);
}
handler(newVal) {
this.$emit('update:currentPage', newVal);
this.lastEmittedPage = -1;
}
},