Skip to content

Commit

Permalink
fix(pagination): duplicate first page button (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonghauhive authored Aug 6, 2024
2 parents 9ddf22f + 9e26a79 commit e43ec0d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/Pagination/sgds-pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ export class SgdsPagination extends SgdsElement {
}

private _renderFirstPage() {
const sanitizeStartPage = this.currentPage - Math.floor(this._sanitizeLimit / 2);
let sanitizeStartPage = this.currentPage - Math.floor(this._sanitizeLimit / 2);

if (this.pages.length - sanitizeStartPage < this.limit) {
sanitizeStartPage = this.pages.length + 1 - this.limit;
}

if (sanitizeStartPage > 1) {
return html`
<li key=${1} class="page-item ${this.currentPage === 1 ? "active" : ""}">
Expand Down
15 changes: 15 additions & 0 deletions test/pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,21 @@ describe("sgds-pagination", () => {
expect(ellipsises?.length).to.equal(1);
expect(ellipsises?.[0]).to.exist;
});
it("showFirstPage set to true and limit set to page.length, no duplicate first page", async () => {
//8 pages, at page 8
const el = (await fixture(
html`
<sgds-pagination dataLength="40" limit="8" itemsPerPage="5" currentPage="8" showFirstPage></sgds-pagination>
`
)) as SgdsPagination;
const pageOne = el.shadowRoot?.querySelectorAll("li")[1];
const pageTwo = el.shadowRoot?.querySelectorAll("li")[2];
const pageThree = el.shadowRoot?.querySelectorAll("li")[3];

expect(pageOne?.textContent).to.contain("1");
expect(pageTwo?.textContent).to.contain("2");
expect(pageThree?.textContent).to.contain("3");
});
it("showLastPage set to true, last page always appears and only last ellipsis shown", async () => {
//8 pages, at page 1
const el = (await fixture(
Expand Down

0 comments on commit e43ec0d

Please sign in to comment.