Skip to content

Conversation

@kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Nov 11, 2025

Eliminated the coercion logic that set RadioButton.Value to the instance when null, allowing Value to be explicitly set to null. Updated related unit test to reflect the new behavior.

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

Eliminated the coercion logic that set RadioButton.Value to the instance when null, allowing Value to be explicitly set to null. Updated related unit test to reflect the new behavior.

Issues Fixed

Fixes #32466

Eliminated the coercion logic that set RadioButton.Value to the instance when null, allowing Value to be explicitly set to null. Updated related unit test to reflect the new behavior.
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Nov 11, 2025
@dotnet-policy-service
Copy link
Contributor

Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@kubaflo kubaflo marked this pull request as ready for review November 11, 2025 14:53
Copilot AI review requested due to automatic review settings November 11, 2025 14:53
@jfversluis
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the automatic coercion of RadioButton.Value from null to the RadioButton instance itself, allowing developers to explicitly set Value to null. This fixes issue #32466 where the previous behavior prevented null values.

Key Changes:

  • Removed the coerceValue callback and constructor initialization that forced Value to default to the RadioButton instance
  • Updated the unit test to verify that Value can now be explicitly set to and remain null

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Controls/src/Core/RadioButton/RadioButton.cs Removed coercion logic from ValueProperty and removed constructor initialization that set Value to this
src/Controls/tests/Core.UnitTests/RadioButtonTests.cs Updated test to verify Value can be explicitly set to null instead of being coerced to the RadioButton instance

@PureWeen PureWeen added this to the .NET 10.0 SR1.1 milestone Nov 12, 2025
@PureWeen PureWeen added the p/0 Current heighest priority issues that we are targeting for a release. label Nov 12, 2025
@PureWeen
Copy link
Member

/rebase

@PureWeen
Copy link
Member

@asi-evin do you have any comments on this fix?

I'm curious about why you'd added this coercion in the first place and wanted to make sure we aren't missing something here.

Also @kubaflo :-)

I asked our friend copilot about this PR and it found one scenario we might want to consider (in a separate PR)

[Fact(Skip = "Known issue: RadioButtonGroupController doesn't check buttons with Value=null when SelectedValue=null. See PR #32489 validation report.")]
		public void CanSelectRadioButtonWithNullValue()
		{
			// This test proves the bug: when you have a RadioButton with Value=null
			// and set SelectedValue=null, the button should be checked (like a "Don't know" option)
			var layout = new Grid();
			layout.SetValue(RadioButtonGroup.GroupNameProperty, "test");

			var radioButtonA = new RadioButton() { Value = "A" };
			var radioButtonB = new RadioButton() { Value = "B" };
			var radioButtonNull = new RadioButton() { Value = null };  // "Don't know" option

			layout.Children.Add(radioButtonA);
			layout.Children.Add(radioButtonB);
			layout.Children.Add(radioButtonNull);

			// First, select "A"
			layout.SetValue(RadioButtonGroup.SelectedValueProperty, "A");
			Assert.True(radioButtonA.IsChecked);
			Assert.False(radioButtonB.IsChecked);
			Assert.False(radioButtonNull.IsChecked);

			// Now select the "Don't know" option by setting SelectedValue to null
			layout.SetValue(RadioButtonGroup.SelectedValueProperty, null);

			// Expected: radioButtonNull should be checked (because its Value is null)
			// Expected: radioButtonA should be unchecked
			Assert.False(radioButtonA.IsChecked, "RadioButton A should be unchecked");
			Assert.False(radioButtonB.IsChecked, "RadioButton B should remain unchecked");
			Assert.True(radioButtonNull.IsChecked, "RadioButton with Value=null should be checked when SelectedValue=null");
		}

@kubaflo
Copy link
Contributor Author

kubaflo commented Nov 13, 2025

@PureWeen yeah my man @copilot is right, and it is an interesting case. I can handle it.

@kubaflo kubaflo self-assigned this Nov 13, 2025
@PureWeen
Copy link
Member

/backport to release/10.0.1xx-sr1

@github-actions
Copy link
Contributor

Started backporting to release/10.0.1xx-sr1 (link to workflow run)

@asi-evin
Copy link
Contributor

@asi-evin do you have any comments on this fix?

I'm curious about why you'd added this coercion in the first place and wanted to make sure we aren't missing something here.

I'll be able to look at this tomorrow or even the weekend, but I took a breif look at my pull request. I didn't find the exact UI test (not unit test, I was mistaken there), but I think I recall it had something to do with multiple radio buttons in the same group all being NULL.

...Or I'm just making this all up in my head, hopefully I can find out tomorrow.

@github-project-automation github-project-automation bot moved this from Todo to Approved in MAUI SDK Ongoing Nov 14, 2025
@jfversluis jfversluis merged commit 68f41a0 into dotnet:main Nov 14, 2025
161 of 169 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Nov 14, 2025
evgenygunko pushed a commit to evgenygunko/CopyWordsDA that referenced this pull request Nov 26, 2025
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [Microsoft.Maui.Controls](https://github.com/dotnet/maui) | nuget | patch | `10.0.10` -> `10.0.11` |

---

### Release Notes

<details>
<summary>dotnet/maui (Microsoft.Maui.Controls)</summary>

### [`v10.0.11`](https://github.com/dotnet/maui/releases/tag/10.0.11): SR1.1

[Compare Source](dotnet/maui@10.0.10...10.0.11)

##### What's Changed

.NET MAUI 10.0.11 introduces significant improvements across all platforms with focus on quality, performance, and developer experience. This release includes 11 commits with various improvements, bug fixes, and enhancements.

##### .NET MAUI Product Fixes

##### Android

-   Fix content page title clipping on Android API < 30 with window insets compatibility by [@&#8203;Copilot](https://github.com/Copilot) in dotnet/maui#32738

    <details>
    <summary>🔧 Fixes</summary>

    -   [Shell content page title position incorrect/clipped](dotnet/maui#32526)

    </details>

##### Button

-   \[release/10.0.1xx-sr1] Removed Value property coercion in RadioButton by [@&#8203;github-actions](https://github.com/github-actions)\[bot] in dotnet/maui#32604

    <details>
    <summary>🔧 Fixes</summary>

    -   [Removed Value property coercion in RadioButton](dotnet/maui#32489)

    </details>

##### DateTimePicker

-   Fix crash when TimePicker.Time is set to null (backport from PR [#&#8203;32660](dotnet/maui#32660)) by [@&#8203;Copilot](https://github.com/Copilot) in dotnet/maui#32715

    <details>
    <summary>🔧 Fixes</summary>

    -   [Fix crash when TimePicker.Time is set to null](dotnet/maui#32660)

    </details>

##### Gestures

-   \[release/10.0.1xx-sr1] predictive back gesture support for Android 13+ by [@&#8203;github-actions](https://github.com/github-actions)\[bot] in dotnet/maui#32635

    <details>
    <summary>🔧 Fixes</summary>

    -   [predictive back gesture support for Android 13+](dotnet/maui#32461)

    </details>

##### Infrastructure

-   \[release/10.0.1xx-sr1] \[ci] Revert changes setting Creator by [@&#8203;github-actions](https://github.com/github-actions)\[bot] in dotnet/maui#32803

    <details>
    <summary>🔧 Fixes</summary>

    -   [\[ci\] Revert changes setting Creator](dotnet/maui#32743)

    </details>

##### Mediapicker

-   \[release/10.0.1xx-sr1] \[Android] Refactor selection limit handling in MediaPicker by [@&#8203;github-actions](https://github.com/github-actions)\[bot] in dotnet/maui#32628

    <details>
    <summary>🔧 Fixes</summary>

    -   [\[Android\] Refactor selection limit handling in MediaPicker](dotnet/maui#32571)

   ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-radiobutton RadioButton, RadioButtonGroup community ✨ Community Contribution p/0 Current heighest priority issues that we are targeting for a release.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Regression] RadioButton should support Null Value

4 participants