From d531dbfff87b7a9c9b2781792e0f6761e5f42324 Mon Sep 17 00:00:00 2001 From: Mukilan IK Date: Sun, 21 Jan 2024 17:48:04 +0530 Subject: [PATCH 1/2] fix(pagination): show page number when there is only 1 page When there is only 1 page the page number is not shown, instead only the disabled buttons are shown. The correct behaviour is to show the active page number (1) and have the buttons disabled. fix #1048 --- src/components/Pagination/Pagination.tsx | 2 +- src/components/Pagination/helpers.spec.ts | 5 ++++- src/components/Pagination/helpers.ts | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/Pagination/Pagination.tsx b/src/components/Pagination/Pagination.tsx index e64cd37c6..2fa121389 100644 --- a/src/components/Pagination/Pagination.tsx +++ b/src/components/Pagination/Pagination.tsx @@ -90,7 +90,7 @@ const PaginationComponent: FC = ({ {showIcon && } {previousLabel} diff --git a/src/components/Pagination/helpers.spec.ts b/src/components/Pagination/helpers.spec.ts index 0abbf043c..cd201ada5 100644 --- a/src/components/Pagination/helpers.spec.ts +++ b/src/components/Pagination/helpers.spec.ts @@ -4,10 +4,13 @@ import { range } from './helpers'; describe('Helpers / Range', () => { it('should return the empty list, given start >= end', () => { expect(range(20, 10)).toEqual([]); - expect(range(10, 10)).toEqual([]); }); it('should return every number from start to end, inclusive, given start < end', () => { expect(range(10, 20)).toEqual([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]); }); + + it('should a single number == start == end, given start == end', () => { + expect(range(10, 10)).toEqual([10]); + }); }); diff --git a/src/components/Pagination/helpers.ts b/src/components/Pagination/helpers.ts index 29e4a4303..4963e4c19 100644 --- a/src/components/Pagination/helpers.ts +++ b/src/components/Pagination/helpers.ts @@ -1,5 +1,5 @@ export const range: (start: number, end: number) => number[] = (start, end) => { - if (start >= end) { + if (start > end) { return []; } From 369556b981a5b47f3001d724ec512d5d3aed4c36 Mon Sep 17 00:00:00 2001 From: Mukilan IK Date: Sun, 21 Jan 2024 18:07:29 +0530 Subject: [PATCH 2/2] refactor(fix type in helper test case): added word 'return' Added word 'return' --- src/components/Pagination/helpers.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Pagination/helpers.spec.ts b/src/components/Pagination/helpers.spec.ts index cd201ada5..e521873d5 100644 --- a/src/components/Pagination/helpers.spec.ts +++ b/src/components/Pagination/helpers.spec.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { range } from './helpers'; describe('Helpers / Range', () => { - it('should return the empty list, given start >= end', () => { + it('should return the empty list, given start > end', () => { expect(range(20, 10)).toEqual([]); }); @@ -10,7 +10,7 @@ describe('Helpers / Range', () => { expect(range(10, 20)).toEqual([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]); }); - it('should a single number == start == end, given start == end', () => { + it('should return a single number == start == end, given start == end', () => { expect(range(10, 10)).toEqual([10]); }); });