From af4e2c153fb1e338ffdafe6fc872638bcff30d70 Mon Sep 17 00:00:00 2001 From: Julia Hillich Date: Tue, 4 Jun 2024 11:08:55 +0200 Subject: [PATCH 1/3] fix: pagination with 0 elements Fixes #2311 --- .../components/pagination/pagination.spec.ts | 20 +++++++++++++++++++ .../src/components/pagination/pagination.tsx | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/components/src/components/pagination/pagination.spec.ts b/packages/components/src/components/pagination/pagination.spec.ts index 33272df330..3f58647aca 100644 --- a/packages/components/src/components/pagination/pagination.spec.ts +++ b/packages/components/src/components/pagination/pagination.spec.ts @@ -125,4 +125,24 @@ describe('pagination', () => { }) ); }); + it('should show no start element when total elements is zero', async () => { + const specPage = await newSpecPage({ + components: [Pagination], + html: ` + `, + }); + const paginationInfoElement = + specPage.root.shadowRoot.querySelector('.pagination__info'); + const buttonPrev = specPage.root.shadowRoot.querySelector( + '.pagination__prev-prompt' + ); + expect(paginationInfoElement.textContent).toEqual('0-0 / 0'); + expect(buttonPrev.hasAttribute('disabled')).toBe(true); + }); }); diff --git a/packages/components/src/components/pagination/pagination.tsx b/packages/components/src/components/pagination/pagination.tsx index 28ef043342..4954da48c3 100644 --- a/packages/components/src/components/pagination/pagination.tsx +++ b/packages/components/src/components/pagination/pagination.tsx @@ -177,9 +177,9 @@ export class Pagination { /* 10. Render */ render() { const total = this.totalElements; - const start = this.startElement + 1; + const start = total === 0 ? 0 : this.startElement + 1; const end = Math.min(this.startElement + this.pageSize, total); - const isAtStart = start === 1; + const isAtStart = start === 1 || total === 0; const isAtEnd = end === total; return ( From 3cce05b4994c03755c16006609aca5ded1760bd7 Mon Sep 17 00:00:00 2001 From: Amir Baghdoust Date: Wed, 16 Oct 2024 18:09:24 +0200 Subject: [PATCH 2/3] Update pagination.spec.ts --- packages/components/src/components/pagination/pagination.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/components/src/components/pagination/pagination.spec.ts b/packages/components/src/components/pagination/pagination.spec.ts index 3f58647aca..76adb5c238 100644 --- a/packages/components/src/components/pagination/pagination.spec.ts +++ b/packages/components/src/components/pagination/pagination.spec.ts @@ -146,3 +146,4 @@ describe('pagination', () => { expect(buttonPrev.hasAttribute('disabled')).toBe(true); }); }); + From e572eb1c79e3560088602b8a7cc695074d231566 Mon Sep 17 00:00:00 2001 From: Amir Baghdoust Date: Wed, 16 Oct 2024 18:12:17 +0200 Subject: [PATCH 3/3] Update pagination.spec.ts --- packages/components/src/components/pagination/pagination.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/components/src/components/pagination/pagination.spec.ts b/packages/components/src/components/pagination/pagination.spec.ts index 76adb5c238..3f58647aca 100644 --- a/packages/components/src/components/pagination/pagination.spec.ts +++ b/packages/components/src/components/pagination/pagination.spec.ts @@ -146,4 +146,3 @@ describe('pagination', () => { expect(buttonPrev.hasAttribute('disabled')).toBe(true); }); }); -