Pagination: reset invalid jumper value (#8408)

* fix pagination jumper value

* fix lint
pull/8458/head
Decade 2017-11-23 11:44:33 +08:00 committed by 杨奕
parent 744478b840
commit 61a937798f
2 changed files with 44 additions and 1 deletions

View File

@ -203,6 +203,17 @@ export default {
handleChange({ target }) {
this.$parent.internalCurrentPage = this.$parent.getValidCurrentPage(target.value);
this.oldValue = null;
this.resetValueIfNeed(target);
},
resetValueIfNeed(target) {
const num = parseInt(target.value, 10);
if (!isNaN(num)) {
if (num < 1) {
target.value = 1;
} else {
this.reassignMaxValue(target);
}
}
},
reassignMaxValue(target) {
if (+target.value > this.$parent.internalPageCount) {

View File

@ -214,6 +214,7 @@ describe('Pagination', () => {
triggerEvent(input, 'change');
setTimeout(() => {
expect(vm.page).to.equal(1);
expect(input.value).to.equal('1');
input.value = 10000;
triggerEvent(input, 'change');
@ -225,7 +226,38 @@ describe('Pagination', () => {
triggerEvent(input, 'change');
setTimeout(() => {
expect(vm.page).to.equal(1);
done();
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);
}, 50);
}, 50);
}, 50);
}, 50);
}, 50);