Skip to content

Commit

Permalink
[Form] Workaround Svelte 5 dispatching change event immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
techniq committed Jul 31, 2024
1 parent f20cb28 commit f419435
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rare-beers-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': patch
---

[Form] Workaround Svelte 5 dispatching `change` event immediately
4 changes: 3 additions & 1 deletion packages/svelte-ux/src/lib/components/Form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import formStore from '../stores/formStore.js';
import { getComponentClasses } from './theme.js';
import { cls } from '../utils/styles.js';
import changeStore from '../stores/changeStore.js';
const dispatch = createEventDispatcher();
Expand All @@ -18,7 +19,8 @@
const [_state, draft, errors] = formStore(initial, { schema });
$: current = draft.current;
$: dispatch('change', $_state);
const changed = changeStore(_state, (value) => dispatch('change', value.current));
$changed; // must subscribe to store to get onChange callbacks
</script>

<form
Expand Down

0 comments on commit f419435

Please sign in to comment.