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

Controlled Checkbox Animation #8

Open
schnubor opened this issue Feb 17, 2021 · 3 comments
Open

Controlled Checkbox Animation #8

schnubor opened this issue Feb 17, 2021 · 3 comments

Comments

@schnubor
Copy link

schnubor commented Feb 17, 2021

Hi,

I was wondering if this component can be controlled and was hoping changing the checked prop would do that, but it doesn't play the animation: https://svelte.dev/repl/97ce63a689d7409c89d7e88899125002?version=3.32.3

Any idea how to correctly play the animation?

Thanks,
Christian

@schnubor schnubor changed the title Controlled Checkbox Controlled Checkbox Animation Feb 17, 2021
@HosseinShabani
Copy link
Owner

@schnubor Hi, This can add so simple. Just add handleChange to export object.

@schnubor
Copy link
Author

schnubor commented Feb 17, 2021

@HosseinShabani Sorry, I don't get it. You got an REPL example?

@schnubor
Copy link
Author

schnubor commented Feb 20, 2021

Solved it. I tried exporting handleChange in various ways now and couldn't get to work (context="module" etc.)

So I figured I fork this and solve it via reactivity, you can check it in my fork: https://github.com/Perspective-Software/svelte-checkbox/blob/master/Checkbox.svelte

I added a new prop called checkedControlled that you can change from outside. The component listens for it, compares it to the current checked state and triggers handleChange if there is a difference. Not sure if it's worth a PR, I'll let @HosseinShabani decide on that, but maybe someone finds it useful.

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

No branches or pull requests

2 participants