diff --git a/src/lib/components/input/Switch.svelte b/src/lib/components/input/Switch.svelte
index 0ef326e7..7ea7058f 100644
--- a/src/lib/components/input/Switch.svelte
+++ b/src/lib/components/input/Switch.svelte
@@ -21,24 +21,49 @@
onselect,
}: Props = $props()
+ let selectedIndex = $state(0)
+ let id = $props.id()
+
+ /* you see id like this to be a super simple
+
+ */
$effect(() => {
- onselect?.(selected)
+ const newIndex = options.findIndex((i) => i === selected)
+ if (newIndex !== -1) {
+ selectedIndex = newIndex
+ }
+ })
+
+ $effect(() => {
+ const newSelected = options[selectedIndex]
+ if (newSelected !== undefined && newSelected !== selected) {
+ selected = newSelected
+ onselect?.(newSelected)
+ }
})
-
{#each options as option, index}
- {@const slctd = selected == option}
- (selected = option)}
- disabled={disabled[index]}
- type="button"
- >
- {optionNames[index] || option}
-
+
{/each}
-
+
{@render children?.({ selected })}
diff --git a/src/lib/components/input/switch/TabButton.svelte b/src/lib/components/input/switch/TabButton.svelte
index baa772a0..7f5ea976 100644
--- a/src/lib/components/input/switch/TabButton.svelte
+++ b/src/lib/components/input/switch/TabButton.svelte
@@ -11,6 +11,7 @@
selected?: boolean
children: Snippet
size?: keyof typeof sizes
+ element?: 'div' | 'a' | 'button'
[key: string]: any
}
@@ -21,12 +22,13 @@
children,
href,
size = 'sm',
+ element = href ? 'a' : 'button',
...rest
}: Props = $props()