Skip to content

Conversation

@metonym
Copy link
Collaborator

@metonym metonym commented Oct 16, 2025

Fixes #1879

Currently, RadioButton cannot be used standalone outside a RadioButtonGroup. Previously, the checked prop was read-only due to an unconditional reactive statement that always synced it with the group's state, even when no group existed.

The fix enables RadioButton to work in two modes:

  1. Within a RadioButtonGroup where the group manages selection state as before
  2. Standalone where the checked prop is fully bindable and can be updated programmatically or via user interaction. This allows developers to use individual radio buttons with bind:checked for simple use cases without requiring the group component.

This is a non-breaking change. Existing RadioButtonGroup tests should work, and new test coverage validates standalone usage.


radio-button-standalone.mov

@metonym metonym merged commit a5053a5 into master Oct 16, 2025
7 checks passed
@metonym metonym deleted the metonym/radiobutton-standalone branch October 16, 2025 17:41
@brunnerh
Copy link
Contributor

Did you see my PR associated with the same issue?

I had some additional logic to notify the other radio buttons, think that was necessary to not have things go out of sync.

Unfortunately the change event does only fire for the newly selected radio button, not for the ones that are automatically unselected; this is why I used document.getElementsByName to find the associated ones.

@metonym
Copy link
Collaborator Author

metonym commented Oct 16, 2025

I haven't.

I had some additional logic to notify the other radio buttons, think that was necessary to not have things go out of sync.

Could you clarify this scenario? If used individually, why would the component itself be responsible for other instantiations?

@brunnerh
Copy link
Contributor

There would not really be much of a point having radio buttons in the first place unless they form a group (regardless of whether they use the group component, which affects layout in ways one might not want).

So if one of the radio buttons is checked, the others will be unchecked and their state should follow. Whether the state actually matters depends on the usage, e.g. if it is form that does not require JS it won't, but otherwise it might. To avoid inconsistent state, my PR sent events to the other instances of the group.

@brunnerh
Copy link
Contributor

Example would be something like this:

<RadioButton name="billing-address-type" value="same"
	labelText="Same address as shipping address" />

<RadioButton name="billing-address-type" value="separate"
	labelText="Separate billing address"
	bind:checked={showBillingAddressFields} />

{#if showBillingAddressFields}
	[Fields]
{/if}

If the second radio is selected, additional fields should be shown.
If then the first radio is selected, the fields should be hidden again.

@brunnerh
Copy link
Contributor

(Looks like you are quite active right now - it would be nice if you could take a look at all the dust collecting PRs.)

@metonym
Copy link
Collaborator Author

metonym commented Oct 19, 2025

Fixed in v0.89.8

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.

RadioButton checked doesn't change

2 participants