Skip to content

Commit

Permalink
fix(pagination): add onChange to page buttons (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
srflp authored Sep 13, 2023
1 parent 9a3a82f commit eac4265
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-coins-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zag-js/pagination": patch
---

Invoke onChange after clicking on numbered pagination buttons
20 changes: 20 additions & 0 deletions e2e/pagination.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,23 @@ test("should update page when prev button is clicked", async ({ page }) => {
await page.click(prevButton)
await expect(page.locator(item2)).toHaveAttribute("aria-current", "page")
})

test("should call onChange when item is clicked", async ({ page }) => {
const onChangeCallbackParams = page.waitForEvent("console")
await page.click(item2)
expect((await onChangeCallbackParams).text()).toContain("page: 2")
})

test("should call onChange when next button is clicked", async ({ page }) => {
const onChangeCallbackParams = page.waitForEvent("console")
await page.click(nextButton)
expect((await onChangeCallbackParams).text()).toContain("page: 2")
})

test("should call onChange when prev button is clicked", async ({ page }) => {
await page.click(item5)

const onChangeCallbackParams = page.waitForEvent("console")
await page.click(prevButton)
expect((await onChangeCallbackParams).text()).toContain("page: 4")
})
4 changes: 2 additions & 2 deletions examples/solid-ts/src/pages/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function Page() {

const api = createMemo(() => pagination.connect(state, send, normalizeProps))

const data = api().slice(paginationData)
const data = () => api().slice(paginationData)

return (
<>
Expand All @@ -39,7 +39,7 @@ export default function Page() {
</tr>
</thead>
<tbody>
<For each={data}>
<For each={data()}>
{(item) => (
<tr>
<td>{item.id}</td>
Expand Down
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 @@ -85,7 +85,7 @@ export function machine(userContext: UserDefinedContext) {
ctx.count = evt.count
},
setPage(ctx, evt) {
ctx.page = evt.page
set.page(ctx, evt.page)
},
setPageSize(ctx, evt) {
ctx.pageSize = evt.size
Expand Down

4 comments on commit eac4265

@vercel
Copy link

@vercel vercel bot commented on eac4265 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on eac4265 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zag-solid – ./examples/solid-ts

zag-solid-chakra-ui.vercel.app
zag-solid.vercel.app
zag-solid-git-main-chakra-ui.vercel.app

@vercel
Copy link

@vercel vercel bot commented on eac4265 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zag-vue – ./examples/vue-ts

zag-vue-chakra-ui.vercel.app
zag-vue-git-main-chakra-ui.vercel.app
zag-vue.vercel.app

@vercel
Copy link

@vercel vercel bot commented on eac4265 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zag-nextjs – ./examples/next-ts

zag-nextjs-chakra-ui.vercel.app
zag-nextjs-git-main-chakra-ui.vercel.app
zag-two.vercel.app

Please sign in to comment.