From 6a99f03e1f014a4dbff884b477a59de90bba3e79 Mon Sep 17 00:00:00 2001 From: Leopoldthecoder Date: Thu, 23 Nov 2017 18:11:28 +0800 Subject: [PATCH] Select: update scroll bar position --- packages/pagination/src/pagination.js | 31 ++++++--------- packages/select/src/select.vue | 2 + packages/theme-chalk/src/button.scss | 2 +- test/unit/specs/pagination.spec.js | 54 +++++++-------------------- 4 files changed, 28 insertions(+), 61 deletions(-) diff --git a/packages/pagination/src/pagination.js b/packages/pagination/src/pagination.js index 783aebad5..cd713d5fc 100644 --- a/packages/pagination/src/pagination.js +++ b/packages/pagination/src/pagination.js @@ -210,34 +210,27 @@ export default { this.oldValue = event.target.value; }, handleBlur({ target }) { - this.reassignMaxValue(target); - }, - handleKeyUp(event) { - const key = event.key || ''; - const keyCode = event.keyCode || ''; - if ((key && key === 'Enter') || (keyCode && keyCode === 13)) { - this.reassignMaxValue(event.target); - this.handleChange(event.target.value); - } + this.resetValueIfNeed(target.value); + this.reassignMaxValue(target.value); }, handleChange(value) { this.$parent.internalCurrentPage = this.$parent.getValidCurrentPage(value); this.oldValue = null; - this.resetValueIfNeed(target); + this.resetValueIfNeed(value); }, - resetValueIfNeed(target) { - const num = parseInt(target.value, 10); + resetValueIfNeed(value) { + const num = parseInt(value, 10); if (!isNaN(num)) { if (num < 1) { - target.value = 1; + this.$refs.input.$el.querySelector('input').value = 1; } else { - this.reassignMaxValue(target); + this.reassignMaxValue(value); } } }, - reassignMaxValue(target) { - if (+target.value > this.$parent.internalPageCount) { - target.value = this.$parent.internalPageCount; + reassignMaxValue(value) { + if (+value > this.$parent.internalPageCount) { + this.$refs.input.$el.querySelector('input').value = this.$parent.internalPageCount; } } }, @@ -253,10 +246,10 @@ export default { value={ this.$parent.internalCurrentPage } domPropsValue={ this.$parent.internalCurrentPage } type="number" + ref="input" onChange={ this.handleChange } onFocus={ this.handleFocus } - onBlur={ this.handleBlur } - nativeOnKeyup={ this.handleKeyUp }/> + onBlur={ this.handleBlur }/> { this.t('el.pagination.pageClassifier') } ); diff --git a/packages/select/src/select.vue b/packages/select/src/select.vue index a7f86252d..052b43afa 100644 --- a/packages/select/src/select.vue +++ b/packages/select/src/select.vue @@ -90,6 +90,7 @@ tag="ul" wrap-class="el-select-dropdown__wrap" view-class="el-select-dropdown__list" + ref="scrollbar" :class="{ 'is-empty': !allowCreate && query && filteredOptionsCount === 0 }" v-show="options.length > 0 && !loading"> { }; changeValue(1); - setTimeout(() => { - expect(vm.page).to.equal(1); - expect(input.value).to.equal('1'); - - changeValue(10000); - + expect(input.value).to.equal(1); + // 多次输入不在min-max区间内的数字 + changeValue(0); setTimeout(() => { - expect(vm.page).to.equal(10); - - changeValue('我好帅'); - + expect(input.value).to.equal(1); + changeValue(0); setTimeout(() => { - expect(vm.page).to.equal(1); - expect(input.value).to.equal('1'); - - // 多次输入不在min-max区间内的数字 - input.value = 0; - triggerEvent(input, 'change'); - setTimeout(()=>{ - expect(vm.page).to.equal(1); - expect(input.value).to.equal('1'); - - input.value = 0; - triggerEvent(input, 'change'); - setTimeout(()=>{ - expect(vm.page).to.equal(1); - expect(input.value).to.equal('1'); - - input.value = 1000; - triggerEvent(input, 'change'); - setTimeout(()=>{ - expect(vm.page).to.equal(10); - expect(input.value).to.equal('10'); - - input.value = 1000; - triggerEvent(input, 'change'); - setTimeout(()=>{ - expect(vm.page).to.equal(10); - expect(input.value).to.equal('10'); - - done(); - }, 50); - }, 50); + expect(input.value).to.equal(1); + changeValue(1000); + setTimeout(() => { + expect(input.value).to.equal(10); + changeValue(1000); + setTimeout(() => { + expect(input.value).to.equal(10); + done(); }, 50); }, 50); }, 50);