fix(module: radio): the disabled parameter for RadioGroup with RadioOption<TValue> options doesn't work (#2744)

* fix(module: radio): the disabled parameter for RadioGroup with `RadioOption<TValue>` options doesn't work

* add test
This commit is contained in:
James Yeung 2022-09-25 17:05:02 +08:00 committed by GitHub
parent 6e1d663a6d
commit 7e051c022c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 12 deletions

View File

@ -18,7 +18,7 @@
{
@foreach (var radio in Options.AsT1)
{
<Radio TValue="TValue" Value="radio.Value" Disabled="radio.Disabled">@radio.Label</Radio>
<Radio Value="radio.Value">@radio.Label</Radio>
}
}
}

View File

@ -1,19 +1,24 @@
@using System.ComponentModel.DataAnnotations
<EnumRadioGroup TEnum="Fruits" @bind-Value="_radioValue"></EnumRadioGroup>
<EnumRadioGroup TEnum="Fruits" @bind-Value="_radioValue" Disabled="_disabled"></EnumRadioGroup>
<br />
Value: @_radioValue
<div style="margin-top: 20px">
<Button Type="primary" OnClick="_=>_disabled=!_disabled">Toggle Disabled</Button>
</div>
@code {
Fruits _radioValue = Fruits.Apple;
Fruits _radioValue = Fruits.Apple;
bool _disabled;
enum Fruits
{
[Display(Name = "🍎 Apple")]
Apple,
enum Fruits
{
[Display(Name = "🍎 Apple")]
Apple,
Pear,
Pear,
Orange
}
Orange
}
}

View File

@ -109,13 +109,38 @@
@<RadioGroup @bind-Value=@value Disabled=@initGroupDisabled>
<Radio Value="1">A</Radio>
<Radio Value="2">B</Radio>
</RadioGroup>
</RadioGroup>
);
var members = radioGroup.FindComponents<Radio<int>>();
//Act
#pragma warning disable BL0005
radioGroup.Instance.Disabled = !initGroupDisabled;
#pragma warning restore BL0005
radioGroup.Render();
//Assert
Assert.All(members, e => Assert.Equal(!initGroupDisabled, e.Instance.Disabled));
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Sync_Disabled_basic_radioGroup_with_options(bool initGroupDisabled)
{
var options = new RadioOption<int>[] { new() { Value = 1, Label = "A" }, new() { Value = 1, Label = "A" } };
//Arrange
int value = 1;
IRenderedComponent<RadioGroup<int>> radioGroup = Render<RadioGroup<int>>(
@<RadioGroup Options="options" @bind-Value=@value Disabled=@initGroupDisabled />
);
var members = radioGroup.FindComponents<Radio<int>>();
//Act
#pragma warning disable BL0005
radioGroup.Instance.Disabled = !initGroupDisabled;
#pragma warning restore BL0005
radioGroup.Render();
//Assert
Assert.All(members, e => Assert.Equal(!initGroupDisabled, e.Instance.Disabled));
}
@ -132,14 +157,18 @@
<Radio Value="1" Disabled=true>A</Radio>
<Radio Value="2">B</Radio>
</RadioGroup>
);
);
var members = radioGroup.FindComponents<Radio<int>>();
//Act
#pragma warning disable BL0005
radioGroup.Instance.Disabled = !initGroupDisabled;
#pragma warning restore BL0005
radioGroup.Render();
//Assert
members[0].Instance.Disabled.Should().BeTrue();
members[1].Instance.Disabled.Should().Be(!initGroupDisabled);
}
}