diff --git a/source/buttons/pagination.test.ts b/source/buttons/pagination.test.ts index d4d794f..b324069 100644 --- a/source/buttons/pagination.test.ts +++ b/source/buttons/pagination.test.ts @@ -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 diff --git a/source/buttons/pagination.ts b/source/buttons/pagination.ts index c52b5fd..5792fce 100644 --- a/source/buttons/pagination.ts +++ b/source/buttons/pagination.ts @@ -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 }