fix(module: radio): Radio in a group should always keep Disabled as same as RadioGroup.Disabled (#2142)

This commit is contained in:
LeaFrock 2021-11-30 14:51:33 +08:00 committed by GitHub
parent 2abb96980b
commit 81027d5267
2 changed files with 22 additions and 12 deletions

View File

@ -93,10 +93,9 @@ namespace AntDesign
.If($"{prefixCls}-button-inner", () => RadioButton);
}
internal void SetName(string name)
{
_name = name;
}
internal void SetName(string name) => _name = name;
internal void SetDisabledValue(bool value) => Disabled = value;
protected override void OnInitialized()
{
@ -109,11 +108,6 @@ namespace AntDesign
RadioGroup?.AddRadio(this);
if (RadioGroup?.Disabled == true)
{
Disabled = true;
}
if (_hasDefaultChecked && !_defaultCheckedSetted)
{
_checked = _defaultChecked;

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using OneOf;
@ -13,7 +12,18 @@ namespace AntDesign
public RenderFragment ChildContent { get; set; }
[Parameter]
public bool Disabled { get; set; }
public bool Disabled
{
get => _disabled;
set
{
if (_disabled != value)
{
_disabled = value;
OnDisabledValueChanged?.Invoke(_disabled);
}
}
}
[Parameter]
public RadioButtonStyle ButtonStyle { get; set; } = RadioButtonStyle.Outline;
@ -38,13 +48,16 @@ namespace AntDesign
[Parameter]
public OneOf<string[], RadioOption<TValue>[]> Options { get; set; }
private List<Radio<TValue>> _radioItems = new List<Radio<TValue>>();
private bool _disabled;
private Action<bool> OnDisabledValueChanged { get; set; }
private TValue _defaultValue;
private bool _hasDefaultValue;
private bool _defaultValueSetted;
private readonly List<Radio<TValue>> _radioItems = new();
private static readonly Dictionary<RadioButtonStyle, string> _buttonStyleDics = new()
{
[RadioButtonStyle.Outline] = "outline",
@ -77,6 +90,8 @@ namespace AntDesign
radio.SetName(Name);
}
_radioItems.Add(radio);
radio.SetDisabledValue(_disabled);
OnDisabledValueChanged += radio.SetDisabledValue;
if (EqualsValue(this.CurrentValue, radio.Value))
{
await radio.Select();
@ -87,6 +102,7 @@ namespace AntDesign
internal void RemoveRadio(Radio<TValue> radio)
{
_radioItems.Remove(radio);
OnDisabledValueChanged -= radio.SetDisabledValue;
}
protected override async Task OnParametersSetAsync()