Skip to content

Commit

Permalink
inlcude name in the id of RadioButotnSolid (fix #665)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesscottbrown committed Jan 2, 2025
1 parent df3655c commit 75a41e7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/multiple-radiobuttongroupsolid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ldn-viz/ui': patch
---

FIXED: include `name` in the `id` of `RadioButtonSolid`, preventing interference with different
`RadioButtonGroupSolid`s that include options with the same `id`.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import { Story } from '@storybook/addon-svelte-csf';
let selectedId = 'bus';
let selectedId2 = 'train';
let optionsForGroup = [
{ id: 'bus', label: 'Bus stops' },
Expand All @@ -30,6 +31,28 @@
<p class="mt-8 text-color-text-secondary">Selected id: {selectedId}</p>
</Story>

<!--
You can create two or more independent instances of the `Two RadioButtonGroupSolid` - just ensure that you provide
different values as the `name` prop.
-->
<Story name="Using multiple instances">
<div class="flex flex-col gap-4">
<div class="flex flex-col gap-1">
<RadioButtonGroupSolid options={optionsForGroup} name="station-type-1" bind:selectedId />
<p class="text-color-text-secondary">Selected id: {selectedId}</p>
</div>

<div class="flex flex-col gap-1">
<RadioButtonGroupSolid
options={optionsForGroup}
name="station-type-2"
bind:selectedId={selectedId2}
/>
<p class="text-color-text-secondary">Selected id: {selectedId2}</p>
</div>
</div>
</Story>

<Story name="RadioGroup with Icons above">
<RadioButtonGroupSolid name="station-type" bind:selectedId>
<RadioButtonSolid id="bus" name="station-type-bus">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
export let disabled = false;
let inputID = `input-${id}`;
let inputID = `input-${name || ''}-${id}`;
const { selectedId } = getContext<{ selectedId: Writable<string> }>('selectedId');
</script>
Expand Down

0 comments on commit 75a41e7

Please sign in to comment.