Skip to content

Commit 68f41a0

Browse files
authored
Removed Value property coercion in RadioButton (#32489)
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.
1 parent bf96ba6 commit 68f41a0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Controls/src/Core/RadioButton/RadioButton.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public partial class RadioButton : TemplatedView, IElementConfiguration<RadioBut
5656
/// <summary>Bindable property for <see cref="Value"/>.</summary>
5757
public static readonly BindableProperty ValueProperty =
5858
BindableProperty.Create(nameof(Value), typeof(object), typeof(RadioButton), null,
59-
propertyChanged: (b, o, n) => ((RadioButton)b).OnValuePropertyChanged(),
60-
coerceValue: (b, o) => o ?? b);
59+
propertyChanged: (b, o, n) => ((RadioButton)b).OnValuePropertyChanged());
6160

6261
/// <summary>Bindable property for <see cref="IsChecked"/>.</summary>
6362
public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(
@@ -210,9 +209,6 @@ public RadioButton()
210209
{
211210
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<RadioButton>>(() =>
212211
new PlatformConfigurationRegistry<RadioButton>(this));
213-
214-
//initialize Value to prevent null value
215-
Value = this;
216212
}
217213

218214
/// <inheritdoc/>

src/Controls/tests/Core.UnitTests/RadioButtonTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,19 @@ public void GroupNullSelectionClearsAnySelection()
305305
}
306306

307307
[Fact]
308-
public void ValuePropertyCoercedToItselfIfSetToNull()
308+
public void ValuePropertyCanBeSetToNull()
309309
{
310310
var radioButton = new RadioButton();
311311

312-
Assert.Equal(radioButton, radioButton.Value);
312+
Assert.Null(radioButton.Value);
313+
314+
radioButton.Value = 1;
315+
316+
Assert.Equal(1, radioButton.Value);
313317

314318
radioButton.Value = null;
315319

316-
Assert.Equal(radioButton, radioButton.Value);
320+
Assert.Null(radioButton.Value);
317321
}
318322
}
319323
}

0 commit comments

Comments
 (0)