Skip to content

Commit

Permalink
fix: pagination page range
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Jan 3, 2025
1 parent 792939f commit ee914e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rich-hotels-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zag-js/pagination": patch
---

Fix issue where page range could return incorrect `end` value when `pageSize` is greater than `count`
2 changes: 1 addition & 1 deletion packages/machines/pagination/src/pagination.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function machine(userContext: UserDefinedContext) {
nextPage: (ctx) => (ctx.page === ctx.totalPages ? null : ctx.page + 1),
pageRange: (ctx) => {
const start = (ctx.page - 1) * ctx.pageSize
const end = start + ctx.pageSize
const end = Math.min(start + ctx.pageSize, ctx.count)
return { start, end }
},
isValidPage: (ctx) => ctx.page >= 1 && ctx.page <= ctx.totalPages,
Expand Down

0 comments on commit ee914e9

Please sign in to comment.