Replies: 2 comments
-
The Svelte integration is still in beta, which is why we moved this to a discussion. I wonder if there's a way to get Svelte state to work with primitive values like |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi! Thanks for the reply. Was able to make this work by using <script lang="ts">
import * as collapsible from "@zag-js/collapsible";
import { normalizeProps, reflect, useMachine } from "@zag-js/svelte";
import { uid } from "uid";
let id = uid();
let open = $state(false);
let context: collapsible.Context = reflect(() => ({
id,
open,
"open.controlled": true,
onOpenChange(detail) {
open = detail.open;
},
}));
let [snapshot, send] = useMachine(collapsible.machine(context), { context });
let api = reflect(() => collapsible.connect(snapshot, send, normalizeProps));
</script> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
🐛 Bug report
Svelte controlled components are not working
💥 Steps to reproduce
$state
that will save the open/closed stateopen
and add anonOpenChange
handler that will update the stateopen.controlled
totrue
💻 Link to reproduction
CodeSandbox reproduction: https://codesandbox.io/p/github/calvo-jp/zagjs-svelte-issue/main?import=true
🧐 Expected behavior
Collapsible will open/close depending on the state
🌍 System information
Beta Was this translation helpful? Give feedback.
All reactions