Skip to content

Commit

Permalink
Fix of back and next page values (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav authored Nov 3, 2023
2 parents 4e82785 + 0b589d4 commit 0ec56b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-teachers-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solid-primitives/pagination": patch
---

Fix of back and next page values
4 changes: 2 additions & 2 deletions packages/pagination/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const createPagination = (
{
disabled: { get: () => page() <= 1, set: noop, enumerable: true },
children: { get: () => opts().prevContent, set: noop, enumerable: true },
page: { get: () => Math.min(1, page() - 1), enumerable: false },
page: { get: () => Math.max(1, page() - 1), enumerable: false },
},
);
const next = Object.defineProperties(
Expand All @@ -187,7 +187,7 @@ export const createPagination = (
{
disabled: { get: () => page() >= opts().pages, set: noop, enumerable: true },
children: { get: () => opts().nextContent, set: noop, enumerable: true },
page: { get: () => Math.max(opts().pages, page() + 1), enumerable: false },
page: { get: () => Math.min(opts().pages, page() + 1), enumerable: false },
},
);
const last = Object.defineProperties(
Expand Down
13 changes: 13 additions & 0 deletions packages/pagination/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ describe("createPagination", () => {
expect(updatedPages.every((page, index) => Object.is(page, initialPages[index]))).toBe(true);
dispose();
}));

test("createPagination next back", () => {
createRoot(dispose => {
const [paginationProps, page, setPage] = createPagination({ pages: 100, maxPages: 1, showFirst: false, initialPage: 3 });
var back = paginationProps()[0]
var next = paginationProps()[2]

expect(back?.page, "back page should be 2").toStrictEqual(2)
expect(next?.page, "next page should be 4").toStrictEqual(4)

dispose();
});
});
});

//@ts-ignore
Expand Down

0 comments on commit 0ec56b0

Please sign in to comment.