Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(RadioButtonGroup): make selected prop reactive #407

Merged
merged 2 commits into from
Nov 22, 2020
Merged

fix(RadioButtonGroup): make selected prop reactive #407

merged 2 commits into from
Nov 22, 2020

Conversation

weaseldotro
Copy link
Contributor

Fixes #406

@weaseldotro weaseldotro requested a review from metonym as a code owner November 22, 2020 10:33
@vercel
Copy link

vercel bot commented Nov 22, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/carbon-svelte/carbon-components-svelte/rnuues5sc
✅ Preview: https://carbon-components-svelte-git-patch-1.carbon-svelte.vercel.app

Copy link
Collaborator

@metonym metonym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.

One requested change. Programmatically setting and binding selected works. However, if the user clicks one of the radio buttons, the update method from the "RadioButtonGroup" context must update selected and not selectedValue.

Otherwise, there may be two or more selected buttons:

Screen Shot 2020-11-22 at 6 23 04 AM

setContext("RadioButtonGroup", {
    selectedValue,
    add: ({ checked, value }) => {
      if (checked) {
        selectedValue.set(value);
      }
    },
    update: (value) => {
+      selected = value;
-       selectedValue.set(value);
    },
  });

@weaseldotro
Copy link
Contributor Author

Oops, somehow I missed testing that. I have added the requested changes.

To correctly test this, in my test program https://codesandbox.io/s/loving-grass-p466p?file=/App.svelte I have replaced <RadioButtonGroup selected={plan}> with <RadioButtonGroup bind:selected={plan}> to use two way binding, otherwise it won't work correctly when using both radios and buttons to change the options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Selected prop on RadioButtonGroup is not reactive
2 participants