From 7120490d3ef684274db07fa1c23eaca9686f778b Mon Sep 17 00:00:00 2001 From: Decade Date: Thu, 23 Nov 2017 11:44:33 +0800 Subject: [PATCH] Pagination: reset invalid jumper value (#8408) * fix pagination jumper value * fix lint --- packages/pagination/src/pagination.js | 11 +++++++++ test/unit/specs/pagination.spec.js | 34 ++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/pagination/src/pagination.js b/packages/pagination/src/pagination.js index abcac3c37..783aebad5 100644 --- a/packages/pagination/src/pagination.js +++ b/packages/pagination/src/pagination.js @@ -223,6 +223,17 @@ export default { handleChange(value) { this.$parent.internalCurrentPage = this.$parent.getValidCurrentPage(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) { diff --git a/test/unit/specs/pagination.spec.js b/test/unit/specs/pagination.spec.js index 44d990f4f..a0ae8b15d 100644 --- a/test/unit/specs/pagination.spec.js +++ b/test/unit/specs/pagination.spec.js @@ -226,6 +226,7 @@ describe('Pagination', () => { setTimeout(() => { expect(vm.page).to.equal(1); + expect(input.value).to.equal('1'); changeValue(10000); @@ -236,7 +237,38 @@ describe('Pagination', () => { 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);