Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/Controls/src/Core/RadioButton/RadioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public partial class RadioButton : TemplatedView, IElementConfiguration<RadioBut
/// <summary>Bindable property for <see cref="Value"/>.</summary>
public static readonly BindableProperty ValueProperty =
BindableProperty.Create(nameof(Value), typeof(object), typeof(RadioButton), null,
propertyChanged: (b, o, n) => ((RadioButton)b).OnValuePropertyChanged(),
coerceValue: (b, o) => o ?? b);
propertyChanged: (b, o, n) => ((RadioButton)b).OnValuePropertyChanged());

/// <summary>Bindable property for <see cref="IsChecked"/>.</summary>
public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(
Expand Down Expand Up @@ -210,9 +209,6 @@ public RadioButton()
{
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<RadioButton>>(() =>
new PlatformConfigurationRegistry<RadioButton>(this));

//initialize Value to prevent null value
Value = this;
}

/// <inheritdoc/>
Expand Down
10 changes: 7 additions & 3 deletions src/Controls/tests/Core.UnitTests/RadioButtonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,19 @@ public void GroupNullSelectionClearsAnySelection()
}

[Fact]
public void ValuePropertyCoercedToItselfIfSetToNull()
public void ValuePropertyCanBeSetToNull()
{
var radioButton = new RadioButton();

Assert.Equal(radioButton, radioButton.Value);
Assert.Null(radioButton.Value);

radioButton.Value = 1;

Assert.Equal(1, radioButton.Value);

radioButton.Value = null;

Assert.Equal(radioButton, radioButton.Value);
Assert.Null(radioButton.Value);
}
}
}