mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-02 12:07:44 +08:00
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:
parent
6e1d663a6d
commit
7e051c022c
@ -18,7 +18,7 @@
|
|||||||
{
|
{
|
||||||
@foreach (var radio in Options.AsT1)
|
@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>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
@using System.ComponentModel.DataAnnotations
|
@using System.ComponentModel.DataAnnotations
|
||||||
|
|
||||||
<EnumRadioGroup TEnum="Fruits" @bind-Value="_radioValue"></EnumRadioGroup>
|
<EnumRadioGroup TEnum="Fruits" @bind-Value="_radioValue" Disabled="_disabled"></EnumRadioGroup>
|
||||||
<br />
|
<br />
|
||||||
Value: @_radioValue
|
Value: @_radioValue
|
||||||
|
|
||||||
|
<div style="margin-top: 20px">
|
||||||
|
<Button Type="primary" OnClick="_=>_disabled=!_disabled">Toggle Disabled</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
Fruits _radioValue = Fruits.Apple;
|
Fruits _radioValue = Fruits.Apple;
|
||||||
|
bool _disabled;
|
||||||
|
|
||||||
enum Fruits
|
enum Fruits
|
||||||
{
|
{
|
||||||
[Display(Name = "🍎 Apple")]
|
[Display(Name = "🍎 Apple")]
|
||||||
Apple,
|
Apple,
|
||||||
|
|
||||||
Pear,
|
Pear,
|
||||||
|
|
||||||
Orange
|
Orange
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -109,13 +109,38 @@
|
|||||||
@<RadioGroup @bind-Value=@value Disabled=@initGroupDisabled>
|
@<RadioGroup @bind-Value=@value Disabled=@initGroupDisabled>
|
||||||
<Radio Value="1">A</Radio>
|
<Radio Value="1">A</Radio>
|
||||||
<Radio Value="2">B</Radio>
|
<Radio Value="2">B</Radio>
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
);
|
);
|
||||||
var members = radioGroup.FindComponents<Radio<int>>();
|
var members = radioGroup.FindComponents<Radio<int>>();
|
||||||
//Act
|
//Act
|
||||||
#pragma warning disable BL0005
|
#pragma warning disable BL0005
|
||||||
radioGroup.Instance.Disabled = !initGroupDisabled;
|
radioGroup.Instance.Disabled = !initGroupDisabled;
|
||||||
#pragma warning restore BL0005
|
#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
|
||||||
Assert.All(members, e => Assert.Equal(!initGroupDisabled, e.Instance.Disabled));
|
Assert.All(members, e => Assert.Equal(!initGroupDisabled, e.Instance.Disabled));
|
||||||
}
|
}
|
||||||
@ -132,14 +157,18 @@
|
|||||||
<Radio Value="1" Disabled=true>A</Radio>
|
<Radio Value="1" Disabled=true>A</Radio>
|
||||||
<Radio Value="2">B</Radio>
|
<Radio Value="2">B</Radio>
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
);
|
);
|
||||||
var members = radioGroup.FindComponents<Radio<int>>();
|
var members = radioGroup.FindComponents<Radio<int>>();
|
||||||
//Act
|
//Act
|
||||||
#pragma warning disable BL0005
|
#pragma warning disable BL0005
|
||||||
radioGroup.Instance.Disabled = !initGroupDisabled;
|
radioGroup.Instance.Disabled = !initGroupDisabled;
|
||||||
#pragma warning restore BL0005
|
#pragma warning restore BL0005
|
||||||
|
|
||||||
|
radioGroup.Render();
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
members[0].Instance.Disabled.Should().BeTrue();
|
members[0].Instance.Disabled.Should().BeTrue();
|
||||||
members[1].Instance.Disabled.Should().Be(!initGroupDisabled);
|
members[1].Instance.Disabled.Should().Be(!initGroupDisabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user