Skip to content

Commit 219459d

Browse files
committed
Test
1 parent 55f2be9 commit 219459d

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/Components/Web/src/Forms/InputRadioContext.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@ namespace Microsoft.AspNetCore.Components.Forms;
88
/// </summary>
99
internal sealed class InputRadioContext
1010
{
11+
private readonly Func<object?> _valueGetter;
12+
1113
public InputRadioContext? ParentContext { get; }
1214
public EventCallback<ChangeEventArgs> ChangeEventCallback { get; }
15+
public object? CurrentValue => _valueGetter();
1316

1417
// Mutable properties that may change any time an InputRadioGroup is rendered
1518
public string? GroupName { get; set; }
16-
public object? CurrentValue { get; set; }
1719
public string? FieldClass { get; set; }
1820

19-
/// <summary>
20-
/// Instantiates a new <see cref="InputRadioContext" />.
21-
/// </summary>
22-
/// <param name="parentContext">The parent context, if any.</param>
23-
/// <param name="changeEventCallback">The event callback to be invoked when the selected value is changed.</param>
24-
public InputRadioContext(InputRadioContext? parentContext, EventCallback<ChangeEventArgs> changeEventCallback)
21+
public InputRadioContext(Func<object?> valueGetter, InputRadioContext? parentContext, EventCallback<ChangeEventArgs> changeEventCallback)
2522
{
23+
_valueGetter = valueGetter;
2624
ParentContext = parentContext;
2725
ChangeEventCallback = changeEventCallback;
2826
}

src/Components/Web/src/Forms/InputRadioGroup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected override void OnParametersSet()
3434
if (_context is null)
3535
{
3636
var changeEventCallback = EventCallback.Factory.CreateBinder<string?>(this, __value => CurrentValueAsString = __value, CurrentValueAsString);
37-
_context = new InputRadioContext(CascadedContext, changeEventCallback);
37+
_context = new InputRadioContext(() => CurrentValue, CascadedContext, changeEventCallback);
3838
}
3939
else if (_context.ParentContext != CascadedContext)
4040
{
@@ -59,7 +59,7 @@ protected override void OnParametersSet()
5959
// Otherwise, just use a GUID to disambiguate this group's radio inputs from any others on the page.
6060
_context.GroupName = _defaultGroupName;
6161
}
62-
_context.CurrentValue = CurrentValue;
62+
6363
_context.FieldClass = EditContext?.FieldCssClass(FieldIdentifier);
6464
}
6565

0 commit comments

Comments
 (0)