Skip to content

Commit

Permalink
fix(pagination): undefined currentPage is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Feb 12, 2019
1 parent 541f7b3 commit 5938f62
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion source/buttons/pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('five pages on fifth page', keysCorrectMacro, 5, 5, [1, 4, 5])
test('go big', keysCorrectMacro, 200, 100, [1, 99, 100, 101, 200])
test('one page is ommited', keysCorrectMacro, 1, 1, [])
test('NaN pages is ommited', keysCorrectMacro, NaN, 1, [])
test('currentPage NaN is ommited', keysCorrectMacro, 5, NaN, [])
test('currentPage NaN is assumed 1', keysCorrectMacro, 2, NaN, [1, 2])
test('currentPage greater than totalPages is max page', keysCorrectMacro, 10, 15, [1, 9, 10])

// When there are 19 items / 2 per page there are... 9.5 pages -> 10
Expand Down
4 changes: 2 additions & 2 deletions source/buttons/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export function paginationOptions(totalPages: number, currentPage: number): {[ke
// Numbers have to be within
// currentPage in [1..totalPages]
const totalPagesFixed = Math.ceil(totalPages)
const currentPageFixed = Math.max(1, Math.min(totalPagesFixed, Math.floor(currentPage)))
const currentPageFixed = Math.max(1, Math.min(totalPagesFixed, Math.floor(currentPage || 1)))

const buttons: any = {}
if (!isFinite(totalPagesFixed) || !isFinite(currentPage) || totalPagesFixed < 2) {
if (!isFinite(totalPagesFixed) || !isFinite(currentPageFixed) || totalPagesFixed < 2) {
return buttons
}

Expand Down

0 comments on commit 5938f62

Please sign in to comment.