diff --git a/components/src/Switcher/Switcher.stories.svelte b/components/src/Switcher/Switcher.stories.svelte
index 6b3f3aff..9ecdac7c 100644
--- a/components/src/Switcher/Switcher.stories.svelte
+++ b/components/src/Switcher/Switcher.stories.svelte
@@ -1,13 +1,15 @@
-
@@ -42,3 +44,29 @@
/>
+
+ {
+ const canvas = within(canvasElement);
+ await step('onchange handler is called', async () => {
+ const optionA = canvas.getByLabelText('Option A');
+ const optionB = canvas.getByLabelText('Option B');
+ await userEvent.click(optionB);
+ expect(onChangeSpy).toHaveBeenCalledTimes(1);
+ await userEvent.click(optionA);
+ expect(onChangeSpy).toHaveBeenCalledTimes(2);
+ });
+ }}
+>
+
+
+
+
diff --git a/components/src/Switcher/Switcher.svelte b/components/src/Switcher/Switcher.svelte
index 0545eae0..7e64b94c 100644
--- a/components/src/Switcher/Switcher.svelte
+++ b/components/src/Switcher/Switcher.svelte
@@ -15,12 +15,22 @@
*/
size?: 'default' | 'small';
/**
- * The currently-selected option
+ * The currently-selected option (bindable)
*/
value: string | null;
+ /**
+ * Fired when the selected value changes (Prefer `value` if possible)
+ */
+ onchange?: (e: Event) => void;
}
- let { label, options, size = 'default', value = $bindable(null) }: SwitcherProps = $props();
+ let {
+ label,
+ options,
+ size = 'default',
+ value = $bindable(null),
+ onchange
+ }: SwitcherProps = $props();
const groupId = $props.id();
const groupName = 'select-' + groupId;
@@ -38,7 +48,14 @@
-
+
{/each}