Skip to content
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
8 changes: 6 additions & 2 deletions src/BootstrapBlazor/Components/Select/SelectTree.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
}
<div @attributes="AdditionalAttributes" id="@Id" class="@ClassName">
<div class="dropdown-toggle" data-bs-toggle="@ToggleString" data-bs-auto-close="outside" data-bs-offset="@OffsetString" data-bs-placement="@PlacementString" data-bs-custom-class="@CustomClassString">
<div class="dropdown-toggle" data-bs-toggle="@ToggleString" data-bs-auto-close="outside" data-bs-offset="@OffsetString" data-bs-placement="@PlacementString" data-bs-custom-class="@SelectTreeCustomClassString">
@if (IsEditable)
{
<input type="text" id="@InputId" disabled="@Disabled" placeholder="@PlaceHolder" class="@InputClassName" value="@CurrentValueAsString" @onchange="@OnChange" />
Expand All @@ -20,7 +20,11 @@
<span class="@AppendClassName"><i class="@DropdownIcon"></i></span>
</div>
<div class="dropdown-menu">
<TreeView TItem="TValue" Items="@Items" ShowIcon="ShowIcon" OnTreeItemClick="OnItemClick" ModelEqualityComparer="@ModelEqualityComparer" CustomKeyAttribute="@CustomKeyAttribute" OnExpandNodeAsync="@OnExpandNodeAsync" />
<TreeView TItem="TValue" Items="@Items" ShowIcon="ShowIcon"
OnTreeItemClick="OnItemClick" ModelEqualityComparer="@ModelEqualityComparer"
ShowSearch="ShowSearch" ShowResetSearchButton="ShowResetSearchButton"
IsFixedSearch="IsFixedSearch"
CustomKeyAttribute="@CustomKeyAttribute" OnExpandNodeAsync="@OnExpandNodeAsync" />
</div>
@if (!IsPopover)
{
Expand Down
22 changes: 22 additions & 0 deletions src/BootstrapBlazor/Components/Select/SelectTree.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ public partial class SelectTree<TValue> : IModelEqualityComparer<TValue>
[Parameter]
public bool IsEditable { get; set; }

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

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

/// <summary>
/// 获得/设置 是否显示重置搜索栏按钮 默认 true 显示
/// </summary>
[Parameter]
public bool ShowResetSearchButton { get; set; } = true;

[Inject]
[NotNull]
private IStringLocalizer<SelectTree<TValue>>? Localizer { get; set; }
Expand Down Expand Up @@ -149,6 +167,10 @@ public partial class SelectTree<TValue> : IModelEqualityComparer<TValue>
[NotNull]
private IIconTheme? IconTheme { get; set; }

private string? SelectTreeCustomClassString => CssBuilder.Default(CustomClassString)
.AddClass("select-tree", IsPopover)
.Build();

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand Down
10 changes: 7 additions & 3 deletions src/BootstrapBlazor/Components/Select/SelectTree.razor.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
.select-tree {
.select-tree {
--bb-select-tree-dropdown-max-height: var(--bb-dropdown-max-height);
}

.select-tree .dropdown-menu {
.dropdown-menu {
max-height: var(--bb-select-tree-dropdown-max-height);

.tree-view {
max-height: calc(var(--bb-select-tree-dropdown-max-height) - var(--bs-dropdown-padding-y) * 2 - 2px);
}
}
}
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/TreeView/TreeView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ else
}
@if (IsVirtualize)
{
<div class="tree-root is-virtual scroll" tabindex="0">
<div class="tree-root is-virtual" tabindex="0">
<Virtualize ItemSize="RowHeight" OverscanCount="10" Items="@Rows">
<ItemContent>
@RenderTreeRow(context)
Expand All @@ -54,7 +54,7 @@ else
}
else
{
<div class="tree-root scroll" tabindex="0">
<div class="tree-root" tabindex="0">
@foreach (var item in Rows)
{
@RenderTreeRow(item)
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
/// <summary>
/// 获得 按钮样式集合
/// </summary>
private string? ClassString => CssBuilder.Default("tree-view")
private string? ClassString => CssBuilder.Default("tree-view scroll")
.AddClass("is-fixed-search", ShowSearch && IsFixedSearch)
.AddClassFromAttributes(AdditionalAttributes)
.Build();
Expand Down
10 changes: 7 additions & 3 deletions src/BootstrapBlazor/Components/TreeView/TreeView.razor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
height: 100%;

.tree-search {
margin-block-end: .5rem;
padding: var(--bb-tree-padding);
padding-bottom: .5rem;
background-color: var(--bs-body-bg);
}

&.is-fixed-search .tree-root {
height: calc(100% - var(--bb-tree-search-height));
&.is-fixed-search .tree-search {
position: sticky;
top: 0;
z-index: 5;
}

.tree-root {
Expand Down
25 changes: 25 additions & 0 deletions test/UnitTest/Components/SelectTreeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,31 @@ public void IsActive_Ok()
Assert.Contains("active", nodes[1].ClassName);
}

[Fact]
public void ShowSearch_Ok()
{
var items = TreeFoo.GetTreeItems();
var cut = Context.RenderComponent<SelectTree<TreeFoo>>(builder =>
{
builder.Add(p => p.Items, items);
builder.Add(p => p.Value, new TreeFoo() { Id = "1020", Text = "Navigation Two" });
builder.Add(p => p.ShowSearch, true);
});
cut.Contains("tree-search");

cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.ShowResetSearchButton, true);
});
cut.Contains("tree-search-reset");

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

private List<TreeViewItem<string>> BindItems { get; } =
[
new TreeViewItem<string>("Test1")
Expand Down
4 changes: 2 additions & 2 deletions test/UnitTest/Components/TreeViewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public async Task IsVirtualize_Ok()
pb.Add(a => a.IsVirtualize, false);
pb.Add(a => a.Items, items);
});
cut.Contains("tree-root scroll");
cut.Contains("tree-root");

cut.SetParametersAndRender(pb =>
{
Expand All @@ -537,7 +537,7 @@ public async Task IsVirtualize_Ok()
return [node1, node2];
});
});
cut.Contains("tree-root is-virtual scroll");
cut.Contains("tree-root is-virtual");

// 触发第一个节点展开
await cut.InvokeAsync(() => cut.Find(".node-icon.visible").Click());
Expand Down
Loading