Skip to content

Commit b852288

Browse files
authored
feat(TreeView): make CanExpandWhenDisabled work if set IsDisabled to true (#7417)
* feat(TreeView): 组件禁止时开启 CanExpandWhenDisabled 仍然可以展开节点 * test: 更新单元测试 * chore: bump version 10.1.5-beta02
1 parent 280d79a commit b852288

5 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.1.5-beta01</Version>
4+
<Version>10.1.5-beta02</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ private async Task OnClick(TreeViewItem<TItem> item)
605605
if (confirm)
606606
{
607607
_activeItem = item;
608-
if (ClickToggleNode && item.CanTriggerClickNode(IsDisabled, CanExpandWhenDisabled))
608+
if (ClickToggleNode)
609609
{
610610
await OnToggleNodeAsync(item);
611611
}

src/BootstrapBlazor/Components/TreeView/TreeViewRow.razor.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -154,9 +154,19 @@ public partial class TreeViewRow<TItem>
154154
.AddClass("visible", Item.HasChildren || Item.Items.Count > 0)
155155
.AddClass(NodeIcon, !Item.IsExpand)
156156
.AddClass(ExpandNodeIcon, Item.IsExpand)
157-
.AddClass("disabled", !CanTriggerClickNode)
157+
.AddClass("disabled", GetDisabledStatus())
158158
.Build();
159159

160+
private bool GetDisabledStatus()
161+
{
162+
if (IsDisabled || Item.IsDisabled)
163+
{
164+
return !CanExpandWhenDisabled;
165+
}
166+
167+
return false;
168+
}
169+
160170
private string? NodeLoadingClassString => CssBuilder.Default("node-icon node-loading")
161171
.AddClass(LoadingIcon)
162172
.Build();
@@ -252,7 +262,7 @@ private async Task OnContextMenu(MouseEventArgs e)
252262
return $"--bb-tree-view-level: {level};";
253263
}
254264

255-
private bool CanTriggerClickNode => Item.CanTriggerClickNode(IsDisabled, CanExpandWhenDisabled);
265+
private bool CanTriggerClickNode => !GetDisabledStatus();
256266

257267
private bool ItemDisabledState => Item.IsDisabled || IsDisabled;
258268

src/BootstrapBlazor/Extensions/TreeViewExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -68,6 +68,4 @@ public static List<TreeViewItem<TItem>> ToFlat<TItem>(this IEnumerable<TreeViewI
6868
}
6969
return rows;
7070
}
71-
72-
internal static bool CanTriggerClickNode<TItem>(this TreeViewItem<TItem> item, bool isDisabled, bool canExpandWhenDisabled) => !isDisabled && (canExpandWhenDisabled || !item.IsDisabled);
7371
}

test/UnitTest/Components/TreeViewTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ public void CanExpandWhenDisabled_Ok()
890890
pb.Add(a => a.IsDisabled, true);
891891
});
892892
node = cut.Find(".node-icon");
893-
Assert.Contains("disabled", node.ClassList);
893+
Assert.DoesNotContain("disabled", node.ClassList);
894894
}
895895

896896
[Fact]

0 commit comments

Comments
 (0)