From 0147489c10dcb0ffdce1ac315d3d6a1441b0c3ac Mon Sep 17 00:00:00 2001 From: Max Kohler Date: Sat, 12 Apr 2025 23:24:59 +0200 Subject: [PATCH] Iterate Switcher, replace groupName prop with built-in .id() --- .../src/Switcher/Switcher.stories.svelte | 9 +- components/src/Switcher/Switcher.svelte | 88 +++++++++---------- 2 files changed, 44 insertions(+), 53 deletions(-) diff --git a/components/src/Switcher/Switcher.stories.svelte b/components/src/Switcher/Switcher.stories.svelte index 622e19a..b4f366b 100644 --- a/components/src/Switcher/Switcher.stories.svelte +++ b/components/src/Switcher/Switcher.stories.svelte @@ -12,13 +12,7 @@ - + @@ -41,7 +35,6 @@ interface SwitcherProps { /** - * Human-readable label for the input. + * Human-readable label */ label: string; - options: string[]; /** - * Machine-readable name for the input. Should be unique across the document. + * Available options */ - groupName: string; + options: string[]; /** - * Type size + * Display size */ size?: 'default' | 'small'; /** @@ -19,18 +18,12 @@ value: string | null; } - let { - label, - options, - groupName, - size = 'default', - value = $bindable(null) - }: SwitcherProps = $props(); + let { label, options, size = 'default', value = $bindable(null) }: SwitcherProps = $props(); + + const groupId = $props.id(); + const groupName = 'select-' + groupId; function optionToID(o: string) { - // TODO: This should use $id() when it comes out, so - // input IDs are guaranteed unique across the app - // See: https://github.com/sveltejs/svelte/issues/13108 return `${groupName}-option-${o.replace(/ /g, '-').toLowerCase()}`; } @@ -42,12 +35,6 @@
  • @@ -56,6 +43,8 @@