Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call custom event handlers #3073

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

phamduylong
Copy link
Contributor

@phamduylong phamduylong commented Dec 19, 2024

Linked Issue

Closes #3064

Description

Call zagProps events whenever applicable

NOTE: onPageSizeChange hasn't worked for Pagination yet.

Changsets

Instructions: Changesets automate our changelog. If you modify files in /packages, run pnpm changeset in the root of the monorepo, follow the prompts, then commit the markdown file. Changes that add features should be minor while chores and bugfixes should be patch. Please prefix the changeset message with feat:, bugfix: or chore:.

Checklist

Please read and apply all contribution requirements.

  • This PR targets the dev branch (NEVER master)
  • Documentation reflects all relevant changes
  • Branch is prefixed with: docs/, feat/, chore/, bugfix/
  • Ensure Svelte and Typescript linting is current - run pnpm ci:check
  • Ensure Prettier linting is current - run pnpm format
  • All test cases are passing - run pnpm test
  • Includes a changeset (if relevant; see above)

Copy link

changeset-bot bot commented Dec 19, 2024

🦋 Changeset detected

Latest commit: e3bff26

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@skeletonlabs/skeleton-svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
skeleton-docs ❌ Failed (Inspect) Dec 19, 2024 11:12pm

Copy link

vercel bot commented Dec 19, 2024

@phamduylong is attempting to deploy a commit to the Skeleton Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@Hugos68 Hugos68 left a comment

Choose a reason for hiding this comment

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

For the Pagination component, the reason the callback in conjunction with binding doesn't work is because the callbacks need to be defined at the context level. Not the machine level.
This makes it work:

const [snapshot, send] = useMachine(
		pagination.machine({
			id: useId(),
			count: data.length,
-			onPageChange(details) {
-				zagProps.onPageChange?.(details);
-				page = details.page;
-			},
-			onPageSizeChange(details) {
-				zagProps.onPageSizeChange?.(details);
-				pageSize = details.pageSize;
-			}
		}),
		{
			context: {
				...zagProps,
+			        onPageChange(details) {
+				        zagProps.onPageChange?.(details);
+				        page = details.page;
+			        },
+			        onPageSizeChange(details) {
+				        zagProps.onPageSizeChange?.(details);
+				       pageSize = details.pageSize;
+			        },
				get page() {
					return page;
				},
				get pageSize() {
					return pageSize;
				},
				get count() {
					// Use 'count' if specified; required for server-side pagination.
					return zagProps.count ?? data.length;
				}
			}
		}
	);

Apart from that, LGTM!

@phamduylong phamduylong marked this pull request as ready for review December 20, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants