Skip to content

Commit 0ec56b0

Browse files
authored
Fix of back and next page values (#537)
2 parents 4e82785 + 0b589d4 commit 0ec56b0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.changeset/plenty-teachers-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solid-primitives/pagination": patch
3+
---
4+
5+
Fix of back and next page values

packages/pagination/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export const createPagination = (
174174
{
175175
disabled: { get: () => page() <= 1, set: noop, enumerable: true },
176176
children: { get: () => opts().prevContent, set: noop, enumerable: true },
177-
page: { get: () => Math.min(1, page() - 1), enumerable: false },
177+
page: { get: () => Math.max(1, page() - 1), enumerable: false },
178178
},
179179
);
180180
const next = Object.defineProperties(
@@ -187,7 +187,7 @@ export const createPagination = (
187187
{
188188
disabled: { get: () => page() >= opts().pages, set: noop, enumerable: true },
189189
children: { get: () => opts().nextContent, set: noop, enumerable: true },
190-
page: { get: () => Math.max(opts().pages, page() + 1), enumerable: false },
190+
page: { get: () => Math.min(opts().pages, page() + 1), enumerable: false },
191191
},
192192
);
193193
const last = Object.defineProperties(

packages/pagination/test/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ describe("createPagination", () => {
8080
expect(updatedPages.every((page, index) => Object.is(page, initialPages[index]))).toBe(true);
8181
dispose();
8282
}));
83+
84+
test("createPagination next back", () => {
85+
createRoot(dispose => {
86+
const [paginationProps, page, setPage] = createPagination({ pages: 100, maxPages: 1, showFirst: false, initialPage: 3 });
87+
var back = paginationProps()[0]
88+
var next = paginationProps()[2]
89+
90+
expect(back?.page, "back page should be 2").toStrictEqual(2)
91+
expect(next?.page, "next page should be 4").toStrictEqual(4)
92+
93+
dispose();
94+
});
95+
});
8396
});
8497

8598
//@ts-ignore

0 commit comments

Comments
 (0)