Skip to content

Commit a24bfe5

Browse files
refactor(TreeView): update clear cache logic (#4955)
* chore: bump version 9.1.9-beta06 Co-Authored-By: XiaoChenDan <[email protected]> * refactor: 更改方法名称 * refactor: 增加父节点赋值操作 * style: 增加定位样式 * revert: 恢复滚动脚本 * chore: 更新注释 * fix: 修复状态不同步问题 * chore: bump version 9.1.9-beta09 --------- Co-authored-by: XiaoChenDan <[email protected]>
1 parent ac8b12d commit a24bfe5

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

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>9.1.9-beta08</Version>
4+
<Version>9.1.9-beta09</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ protected override void OnParametersSet()
355355
protected override async Task OnParametersSetAsync()
356356
{
357357
_rows = null;
358+
TreeNodeStateCache.Reset();
358359

359360
if (Items != null)
360361
{
@@ -875,12 +876,12 @@ private List<TreeViewItem<TItem>> Rows
875876
get
876877
{
877878
// 扁平化数据集合
878-
_rows ??= GetItems().ToFlat<TItem>();
879+
_rows ??= GetTreeItems().ToFlat<TItem>();
879880
return _rows;
880881
}
881882
}
882883

883-
private List<TreeViewItem<TItem>> GetItems() => _searchItems ?? Items;
884+
private List<TreeViewItem<TItem>> GetTreeItems() => _searchItems ?? Items;
884885

885886
private static string? GetTreeRowStyle(TreeViewItem<TItem> item)
886887
{

src/BootstrapBlazor/Components/TreeView/TreeView.razor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function scroll(id, options) {
3232
const el = document.getElementById(id);
3333
const item = el.querySelector(".tree-content.active");
3434
if (item) {
35-
item.parentElement.scrollTo({ top: item.offsetTop, left: 0, behavior: options?.behavior ?? 'smooth' });
35+
item.scrollIntoView(options ?? { behavior: 'smooth', block: 'start', inline: 'nearest' });
3636
}
3737
}
3838

src/BootstrapBlazor/Components/TreeView/TreeView.razor.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
.tree-root {
2929
padding: var(--bb-tree-padding);
3030
margin: var(--bb-tree-margin);
31+
position: relative;
3132
}
3233

3334
.tree-content {

src/BootstrapBlazor/Extensions/TreeViewExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,20 @@ public static class TreeViewExtensions
4949
/// </summary>
5050
/// <typeparam name="TItem"></typeparam>
5151
/// <param name="source"></param>
52+
/// <param name="parent"></param>
5253
/// <returns></returns>
53-
public static List<TreeViewItem<TItem>> ToFlat<TItem>(this IEnumerable<TreeViewItem<TItem>> source)
54+
public static List<TreeViewItem<TItem>> ToFlat<TItem>(this IEnumerable<TreeViewItem<TItem>> source, TreeViewItem<TItem>? parent = null)
5455
{
5556
var rows = new List<TreeViewItem<TItem>>();
5657
if (source != null)
5758
{
5859
foreach (var item in source)
5960
{
61+
item.Parent = parent;
6062
rows.Add(item);
6163
if (item.IsExpand)
6264
{
63-
rows.AddRange(ToFlat(item.Items));
65+
rows.AddRange(ToFlat(item.Items, item));
6466
}
6567
}
6668
}

src/BootstrapBlazor/Options/ScrollIntoViewOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ namespace BootstrapBlazor.Components;
1111
public class ScrollIntoViewOptions
1212
{
1313
/// <summary>
14-
/// 获得/设置 滚动条宽度 默认 5px
14+
/// Determines whether scrolling is instant or animates smoothly
1515
/// </summary>
1616
public ScrollIntoViewBehavior Behavior { get; set; }
1717

1818
/// <summary>
19-
/// 获得/设置 滚动条鼠标悬浮宽度 默认 5px
19+
/// Defines the vertical alignment of the element within the scrollable ancestor container
2020
/// </summary>
2121
public ScrollIntoViewBlock Block { get; set; }
2222

2323
/// <summary>
24-
/// 获得/设置 滚动条鼠标悬浮宽度 默认 5px
24+
/// Defines the horizontal alignment of the element within the scrollable ancestor container
2525
/// </summary>
2626
public ScrollIntoViewInline Inline { get; set; }
2727
}

0 commit comments

Comments
 (0)