Skip to content

Commit

Permalink
[FluentRadioGroup] Fix binding error (#2742)
Browse files Browse the repository at this point in the history
* Fix #2740 by adding value to fluent-radio-group and prevent handling a change when the arg value is empty.

* Fix test
  • Loading branch information
vnbaaij authored Oct 1, 2024
1 parent b9b63c0 commit 4282309
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8084,7 +8084,7 @@
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRadio`1.Context">
<summary>
Gets context for this <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentRadio`1"/>.
Gets context for this <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentRadio`1"/>.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRadio`1.ReadOnly">
Expand Down Expand Up @@ -8137,7 +8137,7 @@
Gets or sets the content to be rendered inside the component.
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentRadio`1.OnInitialized">
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentRadio`1.OnParametersSet">
<inheritdoc />
</member>
<member name="T:Microsoft.FluentUI.AspNetCore.Components.FluentRadioContext">
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Components/List/FluentSelect.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public partial class FluentSelect<TOption> : ListComponentBase<TOption> where TO

private string? GetAriaLabelWithRequired()
{
#pragma warning disable CS0618 // Type or member is obsolete
var label = AriaLabel ?? Label ?? Title ?? string.Empty;
#pragma warning restore CS0618 // Type or member is obsolete

return label + (Required ? $", {RequiredAriaLabel}" : string.Empty);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Components/Radio/FluentRadio.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.FluentUI.AspNetCore.Components;
public partial class FluentRadio<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TValue> : FluentComponentBase
{
/// <summary>
/// Gets context for this <see cref="FluentRadio{TValue}"/>.
/// Gets context for this <see cref="FluentRadio{TValue}"/>.
/// </summary>
internal FluentRadioContext? Context { get; private set; }

Expand Down Expand Up @@ -78,7 +78,7 @@ public FluentRadio()
}

/// <inheritdoc />
protected override void OnInitialized()
protected override void OnParametersSet()
{
Context = string.IsNullOrEmpty(Name) ? CascadedContext : CascadedContext?.FindContextInAncestors(Name);

Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/Radio/FluentRadioGroup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
name="@_context!.GroupName"
orientation="@Orientation.ToAttributeValue()"
required="@Required"
value="@CurrentValueAsString"
@onradiogroupchange="HandleChange"
@attributes="AdditionalAttributes">
@ChildContent
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Components/Radio/FluentRadioGroup.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override void OnParametersSet()
else if (_context.ParentContext != CascadedContext)
{
// This should never be possible in any known usage pattern, but if it happens, we want to know
throw new InvalidOperationException("An FluentRadioGroup cannot change context after creation");
throw new InvalidOperationException("A FluentRadioGroup cannot change context after creation");
}

// Mutate the FluentRadioContext instance in place. Since this is a non-fixed cascading parameter, the descendant
Expand All @@ -65,7 +65,7 @@ protected override bool TryParseValueFromString(string? value, [MaybeNullWhen(fa

private void HandleChange(ChangeEventArgs e)
{
if (CurrentValueAsString != e?.Value?.ToString())
if (CurrentValueAsString != e?.Value?.ToString() && e?.Value is not null)
{
CurrentValueAsString = e?.Value?.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

<fluent-radio-group id="xxx" name="xxx" blazor:onradiogroupclick="1" blazor:elementreference="xxx">
<fluent-radio-group id="xxx" name="xxx" value="False" blazor:onradiogroupclick="1" blazor:elementreference="xxx">
<b>render me</b>
</fluent-radio-group>

0 comments on commit 4282309

Please sign in to comment.