From 10b3346c4f94e1a99f9c5dd6cc1229d430fe384f Mon Sep 17 00:00:00 2001 From: James Yeung Date: Tue, 23 Mar 2021 12:59:20 +0800 Subject: [PATCH] fix(module: cascader): style and class properties (#1269) --- components/cascader/Cascader.razor | 6 ++-- components/cascader/Cascader.razor.cs | 52 ++++++++++----------------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/components/cascader/Cascader.razor b/components/cascader/Cascader.razor index a8eb5c89..3d0fef03 100644 --- a/components/cascader/Cascader.razor +++ b/components/cascader/Cascader.razor @@ -3,7 +3,6 @@ @inherits AntInputComponentBase -
- + - + @if (string.IsNullOrWhiteSpace(Value) || !ShowClearIcon) { @@ -73,5 +72,4 @@
-
\ No newline at end of file diff --git a/components/cascader/Cascader.razor.cs b/components/cascader/Cascader.razor.cs index b9797b2f..02810af3 100644 --- a/components/cascader/Cascader.razor.cs +++ b/components/cascader/Cascader.razor.cs @@ -77,7 +77,7 @@ namespace AntDesign else if (_nodelist.Count != 0) _nodelist.Clear(); _nodelist.AddRange(value); - _optionsNeedInitialize = true; + ProcessParentAndDefault(); } } @@ -98,9 +98,6 @@ namespace AntDesign /// internal List _renderNodes = new List(); - private string _pickerSizeClass = string.Empty; - private string _inputSizeClass = string.Empty; - /// /// 浮层 展开/折叠状态 /// @@ -117,36 +114,28 @@ namespace AntDesign /// private SelectedTypeEnum SelectedType { get; set; } + private ClassMapper _inputClassMapper = new ClassMapper(); private string _displayText; - private bool _optionsNeedInitialize; + + private static Hashtable _sizeMap = new Hashtable() + { + ["large"] = "lg", + ["small"] = "sm" + }; protected override void OnInitialized() { base.OnInitialized(); - } - protected override void OnParametersSet() - { - base.OnParametersSet(); + ClassMapper.Add("ant-cascader-picker") + .GetIf(() => $"ant-cascader-picker-{Size}", () => _sizeMap.ContainsKey(Size)) + .GetIf(() => $"ant-input-{_sizeMap[Size]}", () => _sizeMap.ContainsKey(Size)) + ; - Hashtable sizeMap = new Hashtable() - { - ["large"] = "lg", - ["small"] = "sm" - }; - - if (sizeMap.ContainsKey(Size)) - { - _pickerSizeClass = $"ant-cascader-picker-{Size}"; - _inputSizeClass = $"ant-input-{sizeMap[Size]}"; - } - else - { - _pickerSizeClass = ""; - _inputSizeClass = ""; - } - - ProcessParentAndDefault(); + _inputClassMapper + .Add("ant-input") + .Add("ant-cascader-input") + .GetIf(() => $"ant-input-{_sizeMap[Size]}", () => _sizeMap.ContainsKey(Size)); } protected override void OnValueChange(string value) @@ -310,13 +299,8 @@ namespace AntDesign /// private void ProcessParentAndDefault() { - if (_optionsNeedInitialize) - { - _optionsNeedInitialize = false; - - InitCascaderNodeState(_nodelist, null, 0); - SetDefaultValue(Value ?? DefaultValue); - } + InitCascaderNodeState(_nodelist, null, 0); + SetDefaultValue(Value ?? DefaultValue); } ///