Replies: 3 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.
-
|
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.
-
|
Closing — the Svelte adapter was significantly reworked in v1.0. Please open a new discussion if this persists. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
🐛 Bug report
Svelte controlled components are not working
💥 Steps to reproduce
$statethat will save the open/closed stateopenand add anonOpenChangehandler that will update the stateopen.controlledtotrue💻 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