fix(module: cascader): style and class properties (#1269)

This commit is contained in:
James Yeung 2021-03-23 12:59:20 +08:00 committed by GitHub
parent e5225afb05
commit 10b3346c4f
2 changed files with 20 additions and 38 deletions

View File

@ -3,7 +3,6 @@
@inherits AntInputComponentBase<string> @inherits AntInputComponentBase<string>
<CascadingValue Value=@("ant-cascader-menus") Name="PrefixCls"> <CascadingValue Value=@("ant-cascader-menus") Name="PrefixCls">
<div class="@ClassMapper.Class" style="@Style" id="@Id" tabindex="-1" @ref="Ref">
<OverlayTrigger Visible="@(ToggleState && _nodelist != null && _nodelist.Any())" <OverlayTrigger Visible="@(ToggleState && _nodelist != null && _nodelist.Any())"
ComplexAutoCloseAndVisible="true" ComplexAutoCloseAndVisible="true"
Trigger="new[] { TriggerType.Click }" Trigger="new[] { TriggerType.Click }"
@ -11,9 +10,9 @@
OverlayEnterCls="ant-slide-up-enter ant-slide-up-enter-active ant-slide-up" OverlayEnterCls="ant-slide-up-enter ant-slide-up-enter-active ant-slide-up"
OverlayLeaveCls="ant-slide-up-leave ant-slide-up-leave-active ant-slide-up"> OverlayLeaveCls="ant-slide-up-leave ant-slide-up-leave-active ant-slide-up">
<Unbound> <Unbound>
<span @ref="context.Current" class="ant-cascader-picker @_pickerSizeClass" tabindex="1" @onclick="InputOnToggle" @onblur="CascaderOnBlur" @onmouseover="InputOnMouseOver" @onmouseout="InputOnMouseOut"> <span @ref="context.Current" style="@Style" id="@Id" class="@ClassMapper.Class" tabindex="1" @onclick="InputOnToggle" @onblur="CascaderOnBlur" @onmouseover="InputOnMouseOver" @onmouseout="InputOnMouseOut">
<span class="ant-cascader-picker-label"></span> <span class="ant-cascader-picker-label"></span>
<input autocomplete="off" tabindex="-1" placeholder="@PlaceHolder" class="ant-input ant-cascader-input @_inputSizeClass" readonly="@Readonly" type="text" value="@_displayText"> <input autocomplete="off" tabindex="-1" placeholder="@PlaceHolder" class="@_inputClassMapper.Class" readonly="@Readonly" type="text" value="@_displayText">
@if (string.IsNullOrWhiteSpace(Value) || !ShowClearIcon) @if (string.IsNullOrWhiteSpace(Value) || !ShowClearIcon)
{ {
<Icon Type="down" Class="@($"ant-cascader-picker-arrow {(ToggleState ? "ant-cascader-picker-arrow-expand" : string.Empty)}")" /> <Icon Type="down" Class="@($"ant-cascader-picker-arrow {(ToggleState ? "ant-cascader-picker-arrow-expand" : string.Empty)}")" />
@ -73,5 +72,4 @@
</div> </div>
</Overlay> </Overlay>
</OverlayTrigger> </OverlayTrigger>
</div>
</CascadingValue> </CascadingValue>

View File

@ -77,7 +77,7 @@ namespace AntDesign
else if (_nodelist.Count != 0) _nodelist.Clear(); else if (_nodelist.Count != 0) _nodelist.Clear();
_nodelist.AddRange(value); _nodelist.AddRange(value);
_optionsNeedInitialize = true; ProcessParentAndDefault();
} }
} }
@ -98,9 +98,6 @@ namespace AntDesign
/// </summary> /// </summary>
internal List<CascaderNode> _renderNodes = new List<CascaderNode>(); internal List<CascaderNode> _renderNodes = new List<CascaderNode>();
private string _pickerSizeClass = string.Empty;
private string _inputSizeClass = string.Empty;
/// <summary> /// <summary>
/// 浮层 展开/折叠状态 /// 浮层 展开/折叠状态
/// </summary> /// </summary>
@ -117,36 +114,28 @@ namespace AntDesign
/// </summary> /// </summary>
private SelectedTypeEnum SelectedType { get; set; } private SelectedTypeEnum SelectedType { get; set; }
private ClassMapper _inputClassMapper = new ClassMapper();
private string _displayText; private string _displayText;
private bool _optionsNeedInitialize;
protected override void OnInitialized() private static Hashtable _sizeMap = new Hashtable()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
base.OnParametersSet();
Hashtable sizeMap = new Hashtable()
{ {
["large"] = "lg", ["large"] = "lg",
["small"] = "sm" ["small"] = "sm"
}; };
if (sizeMap.ContainsKey(Size)) protected override void OnInitialized()
{ {
_pickerSizeClass = $"ant-cascader-picker-{Size}"; base.OnInitialized();
_inputSizeClass = $"ant-input-{sizeMap[Size]}";
}
else
{
_pickerSizeClass = "";
_inputSizeClass = "";
}
ProcessParentAndDefault(); ClassMapper.Add("ant-cascader-picker")
.GetIf(() => $"ant-cascader-picker-{Size}", () => _sizeMap.ContainsKey(Size))
.GetIf(() => $"ant-input-{_sizeMap[Size]}", () => _sizeMap.ContainsKey(Size))
;
_inputClassMapper
.Add("ant-input")
.Add("ant-cascader-input")
.GetIf(() => $"ant-input-{_sizeMap[Size]}", () => _sizeMap.ContainsKey(Size));
} }
protected override void OnValueChange(string value) protected override void OnValueChange(string value)
@ -310,14 +299,9 @@ namespace AntDesign
/// </summary> /// </summary>
private void ProcessParentAndDefault() private void ProcessParentAndDefault()
{ {
if (_optionsNeedInitialize)
{
_optionsNeedInitialize = false;
InitCascaderNodeState(_nodelist, null, 0); InitCascaderNodeState(_nodelist, null, 0);
SetDefaultValue(Value ?? DefaultValue); SetDefaultValue(Value ?? DefaultValue);
} }
}
/// <summary> /// <summary>
/// 初始化节点属性(Level, ParentNode) /// 初始化节点属性(Level, ParentNode)