Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TreeView): add IsFixedSearch parameter #3772

Merged
merged 5 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions src/BootstrapBlazor.Server/Components/Samples/TreeViews.razor
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@
<TreeView TItem="TreeFoo" Items="@SearchItems" ShowSearch="true" OnSearchAsync="@OnSearchAsync"></TreeView>
</DemoBlock>

<DemoBlock Title="@Localizer["TreeViewFixedSearchTitle"]"
Introduction="@Localizer["TreeViewFixedSearchIntro"]"
Name="IsFixedSearch">
<TreeView TItem="TreeFoo" Items="@SearchItems" ShowSearch="true" OnSearchAsync="@OnSearchAsync" IsFixedSearch="true" style="height: 180px;"></TreeView>
</DemoBlock>

<AttributeTable Items="@GetAttributes()"></AttributeTable>

<AttributeTable Items="@GetTreeItemAttributes()" Title="@Localizer["TreeViewsAttribute"]"></AttributeTable>
2 changes: 2 additions & 0 deletions src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@
"TreeViewShowSkeletonButtonText": "Asynchronous loading",
"TreeViewShowSearchTitle": "Show search",
"TreeViewShowSearchIntro": "By setting <code>ShowSearch</code> to display the search bar, and using the <code>OnSearchAsync</code> callback method to set the data source to refresh the page",
"TreeViewFixedSearchTitle": "Fixed search",
"TreeViewFixedSearchIntro": "The search bar can be fixed by setting <code>IsFixedSearch=\"true\"</code>, and the search bar height can be set by the css variable <code>--bb-tree-search-height</code>",
"TreeViewSetActiveTitle": "Set Active Node",
"TreeViewSetActiveIntro": "Set the currently active node by calling the <code>SetActiveItem</code> method",
"TreeViewSetActiveDisplayText": "Current Active Node",
Expand Down
2 changes: 2 additions & 0 deletions src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@
"TreeViewShowSkeletonButtonText": "异步加载",
"TreeViewShowSearchTitle": "显示搜索栏",
"TreeViewShowSearchIntro": "通过设置 <code>ShowSearch</code> 显示搜索栏,通过 <code>OnSearchAsync</code> 回调方法设置数据源刷新页面即可",
"TreeViewFixedSearchTitle": "固定搜索栏",
"TreeViewFixedSearchIntro": "通过设置 <code>IsFixedSearch=\"true\"</code> 固定搜索栏,可通过样式变量 <code>--bb-tree-search-height</code> 设定搜索栏高度",
"TreeViewSetActiveTitle": "设置激活节点",
"TreeViewSetActiveIntro": "通过调用 <code>SetActiveItem</code> 方法设置当前激活节点",
"TreeViewSetActiveDisplayText": "当前激活节点",
Expand Down
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>8.7.1-beta03</Version>
<Version>8.7.1-beta04</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/TreeView/TreeView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ else
@SearchTemplate
}
}
<ul class="tree-root">
<ul class="tree-root scroll">
@foreach (var item in Items)
{
@RenderTreeItem(item)
Expand Down
7 changes: 7 additions & 0 deletions src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
/// 获得 按钮样式集合
/// </summary>
private string? ClassString => CssBuilder.Default("tree-view")
.AddClass("is-fixed-search", ShowSearch && IsFixedSearch)
.AddClassFromAttributes(AdditionalAttributes)
.Build();

Expand Down Expand Up @@ -127,6 +128,12 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
[Parameter]
public bool ShowSearch { get; set; }

/// <summary>
/// 获得/设置 是否固定搜索栏 默认 false 不固定
/// </summary>
[Parameter]
public bool IsFixedSearch { get; set; }

/// <summary>
/// 获得/设置 是否显示重置搜索栏按钮 默认 true 显示
/// </summary>
Expand Down
8 changes: 7 additions & 1 deletion src/BootstrapBlazor/Components/TreeView/TreeView.razor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
--bb-tree-item-active-bg: #{$bb-tree-item-active-bg};
--bb-tree-item-hover-bg: #{$bb-tree-item-hover-bg};
--bb-tree-icon-margin-right: #{$bb-tree-icon-margin-right};
--bb-tree-disabled-opacity: .5;
--bb-tree-disabled-opacity: #{$bb-tree-disabled-opacity};
--bb-tree-search-height: #{$bb-tree-search-height};
position: relative;
height: 100%;

.tree-search {
margin-bottom: .5rem;
Expand All @@ -23,6 +25,10 @@
margin: var(--bb-tree-margin);
}

.tree-view.is-fixed-search .tree-root {
height: calc(100% - var(--bb-tree-search-height));
}

.tree-view .tree-ul {
padding: 0 0 0 var(--bb-tree-ul-padding-left);
display: none;
Expand Down
2 changes: 2 additions & 0 deletions src/BootstrapBlazor/wwwroot/scss/theme/bootstrap.blazor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ $bb-tree-item-active-color: var(--bs-body-color);
$bb-tree-item-active-bg: rgba(var(--bs-body-color-rgb),.08);
$bb-tree-item-hover-bg: rgba(var(--bs-body-color-rgb),.12);
$bb-tree-icon-margin-right: .5rem;
$bb-tree-search-height: 43px;
$bb-tree-disabled-opacity: .5;

// Upload
$bb-upload-body-margin-top: 10px;
Expand Down
6 changes: 6 additions & 0 deletions test/UnitTest/Components/TreeViewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,12 @@ public void ShowSearch_Ok()
});
});
cut.Contains("search-template");

cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.IsFixedSearch, true);
});
cut.Contains("is-fixed-search");
}

[Fact]
Expand Down