Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>10.2.3</Version>
<Version>10.2.4-beta01</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
17 changes: 17 additions & 0 deletions src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
[Parameter]
public bool EnableKeyboard { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 是否将 active 选中节点自动滚动到可视状态</para>
/// <para lang="en">Gets or sets whether to automatically scroll the active selected node into the visible state.</para>
/// </summary>
[Parameter]
public bool IsAutoScrollIntoView { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 键盘导航时的滚动至视图选项,默认为 null,使用 { behavior: "smooth", block: "nearest", inline: "start" }</para>
/// <para lang="en">Gets or sets the scroll into view options for keyboard navigation. Default is null, using { behavior: "smooth", block: "nearest", inline: "start" }</para>
Expand Down Expand Up @@ -350,6 +357,7 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
private string? _searchText;
private bool _shouldRender = true;
private bool _init;
private bool _scrollIntoView = false;

/// <summary>
/// <inheritdoc/>
Expand Down Expand Up @@ -410,6 +418,7 @@ protected override async Task OnParametersSetAsync()
_activeItem ??= Items.FirstOrDefaultActiveItem();
_activeItem?.SetParentExpand<TreeViewItem<TItem>, TItem>(true);
_init = true;
_scrollIntoView = true;
}
}
}
Expand All @@ -424,6 +433,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

if (_keyboardArrowUpDownTrigger)
{
_scrollIntoView = false;
_keyboardArrowUpDownTrigger = false;
await InvokeVoidAsync("scroll", Id, ScrollIntoViewOptions);
}
Expand All @@ -432,6 +442,12 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await InvokeVoidAsync("resetTreeViewRow", Id);
}

if (IsAutoScrollIntoView && _scrollIntoView)
{
_scrollIntoView = false;
await InvokeVoidAsync("scroll", Id, ScrollIntoViewOptions);
}
Comment thread
ArgoZhang marked this conversation as resolved.
}

/// <summary>
Expand Down Expand Up @@ -703,6 +719,7 @@ public void SetActiveItem(TreeViewItem<TItem>? item)
{
_activeItem = item;
_activeItem?.SetParentExpand<TreeViewItem<TItem>, TItem>(true);
_scrollIntoView = true;
StateHasChanged();
}

Expand Down
Loading