mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-11-30 02:58:13 +08:00
fix(module: TreeSelect): value binding on datasource was changed (#3492)
* fix(module: TreeSelect): value binding on datasource was changed * update selection after value changed * tree datasource change * invoke state changed * clean up * clean up
This commit is contained in:
parent
ede6b57f36
commit
6f6b75835a
@ -751,6 +751,7 @@ namespace AntDesign
|
||||
{
|
||||
SelectedOptionItems.Add(selectOption);
|
||||
}
|
||||
|
||||
selectOption.IsSelected = true;
|
||||
CurrentValue = selectOption.Value;
|
||||
InvokeOnSelectedItemChanged(selectOption);
|
||||
|
@ -25,7 +25,7 @@
|
||||
<div class="" style="max-height: @PopupContainerMaxHeight; overflow-y: auto;">
|
||||
<div>
|
||||
<div class="" role="listbox" style="display: flex; flex-direction: column;">
|
||||
<CascadingValue Name="IsTreeSelect" Value="true" IsFixed="true">
|
||||
<CascadingValue Name="TreeSelect" Value="this" IsFixed="true">
|
||||
<Tree @ref="_tree"
|
||||
TItem="TItem"
|
||||
BlockNode
|
||||
|
@ -14,7 +14,7 @@ using System.Linq;
|
||||
|
||||
namespace AntDesign
|
||||
{
|
||||
public partial class TreeSelect<TItem> : SelectBase<string, TItem> where TItem : class
|
||||
public partial class TreeSelect<TItem> : SelectBase<string, TItem>
|
||||
{
|
||||
[Parameter] public bool ShowExpand { get; set; } = true;
|
||||
|
||||
@ -137,6 +137,7 @@ namespace AntDesign
|
||||
private readonly string _dir = "ltr";
|
||||
private Tree<TItem> _tree;
|
||||
|
||||
[Parameter]
|
||||
public override string Value
|
||||
{
|
||||
get => base.Value;
|
||||
@ -156,6 +157,7 @@ namespace AntDesign
|
||||
}
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
public override IEnumerable<string> Values
|
||||
{
|
||||
get => base.Values;
|
||||
@ -442,6 +444,23 @@ namespace AntDesign
|
||||
;
|
||||
}
|
||||
|
||||
// bind the option once after fetching the data source asynchronously
|
||||
// fixed https://github.com/ant-design-blazor/ant-design-blazor/issues/3446
|
||||
internal void UpdateValueAfterDataSourceChanged()
|
||||
{
|
||||
if (Value != null)
|
||||
{
|
||||
UpdateValueAndSelection();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
if (Values != null)
|
||||
{
|
||||
UpdateValuesSelection();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateValueAndSelection()
|
||||
{
|
||||
if (SelectOptionItems.Any(o => o.Value == Value))
|
||||
|
@ -16,8 +16,8 @@ namespace AntDesign
|
||||
{
|
||||
public partial class Tree<TItem> : AntDomComponentBase
|
||||
{
|
||||
[CascadingParameter(Name = "IsTreeSelect")]
|
||||
public bool IsTreeSelect { get; set; }
|
||||
[CascadingParameter(Name = "TreeSelect")]
|
||||
public TreeSelect<TItem> TreeSelect { get; set; }
|
||||
|
||||
#region fields
|
||||
|
||||
@ -31,6 +31,10 @@ namespace AntDesign
|
||||
/// </summary>
|
||||
private ConcurrentDictionary<long, TreeNode<TItem>> _checkedNodes = new ConcurrentDictionary<long, TreeNode<TItem>>();
|
||||
|
||||
|
||||
bool _nodeHasChanged;
|
||||
|
||||
|
||||
#endregion fields
|
||||
|
||||
#region Tree
|
||||
@ -139,12 +143,26 @@ namespace AntDesign
|
||||
/// Add a node
|
||||
/// </summary>
|
||||
/// <param name="treeNode"></param>
|
||||
internal void AddNode(TreeNode<TItem> treeNode)
|
||||
internal void AddChildNode(TreeNode<TItem> treeNode)
|
||||
{
|
||||
treeNode.NodeIndex = ChildNodes.Count;
|
||||
ChildNodes.Add(treeNode);
|
||||
}
|
||||
|
||||
internal void AddNode(TreeNode<TItem> treeNode)
|
||||
{
|
||||
_allNodes.Add(treeNode);
|
||||
_nodeHasChanged = true;
|
||||
CallAfterRender(async () =>
|
||||
{
|
||||
if (_nodeHasChanged)
|
||||
{
|
||||
_nodeHasChanged = false;
|
||||
TreeSelect?.UpdateValueAfterDataSourceChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#endregion Node
|
||||
|
||||
#region Selected
|
||||
@ -818,7 +836,7 @@ namespace AntDesign
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
if (IsTreeSelect)
|
||||
if (TreeSelect is not null)
|
||||
{
|
||||
IsCtrlKeyDown = true;
|
||||
}
|
||||
|
@ -933,11 +933,12 @@ namespace AntDesign
|
||||
ParentNode.AddNode(this);
|
||||
else
|
||||
{
|
||||
TreeComponent.AddNode(this);
|
||||
TreeComponent.AddChildNode(this);
|
||||
if (!TreeComponent.DefaultExpandAll && TreeComponent.DefaultExpandParent)
|
||||
Expand(true);
|
||||
}
|
||||
TreeComponent._allNodes.Add(this);
|
||||
|
||||
TreeComponent.AddNode(this);
|
||||
|
||||
if (TreeComponent.DisabledExpression != null)
|
||||
Disabled = TreeComponent.DisabledExpression(this);
|
||||
|
Loading…
Reference in New Issue
Block a user