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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@

<DemoBlock Title="@Localizer["SelectTreesEditTitle"]"
Introduction="@Localizer["SelectTreesEditIntro"]"
Name="Edit">
Name="IsEditable">
<section ignore>
<div>@((MarkupString)Localizer["SelectTreesEditDesc"].Value)</div>
</section>
<div class="row g-3">
<div class="col-12 col-sm-6">
<SelectTree Items="EditItems" @bind-Value="@Value" IsEditable="true"></SelectTree>
Expand Down
1 change: 1 addition & 0 deletions src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4891,6 +4891,7 @@
"SelectTreesClientValidationIntro": "validate the value when submit the form. Inside <code>ValidateForm</code>",
"SelectTreesEditTitle": "Edit",
"SelectTreesEditIntro": "By setting <code>IsEditable=\"true\"</code> you can edit the input textbox",
"SelectTreesEditDesc": "After setting <code>IsEditable=\"true\"</code>, the content displayed in the text box is the <code>Value</code> value of the node selected in the <code>TreeView</code>, the input value may not be in the <code>Items</code> collection",
"SelectTreesIsPopoverTitle": "IsPopover",
"SelectTreesIsPopoverIntro": "Set <code>IsPopover</code> to <b>true</b>, use popover render UI prevent The dropdown menu cannot be fully displayed because the parent container is set to <code>overflow: hidden</code>",
"SelectTreesClientValidationButtonText": "Submit"
Expand Down
1 change: 1 addition & 0 deletions src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -4893,6 +4893,7 @@
"SelectTreesClientValidationIntro": "组件内置 <code>ValidateForm</code> 可设置验证规则",
"SelectTreesEditTitle": "可输入",
"SelectTreesEditIntro": "通过设置 <code>IsEditable=\"true\"</code> 可设置下拉框选择后文本框可输入",
"SelectTreesEditDesc": "设置 <code>IsEditable=\"true\"</code> 后,文本框显示的内容为 <code>TreeView</code> 选中节点的 <code>Value</code> 值,输入值可以不在 <code>Items</code> 集合中",
"SelectTreesIsPopoverTitle": "悬浮弹窗",
"SelectTreesIsPopoverIntro": "通过设置 <code>IsPopover</code> 参数,组件使用 <code>popover</code> 渲染 <code>UI</code> 防止由于父容器设置 <code>overflow: hidden;</code> 使弹窗无法显示问题",
"SelectTreesClientValidationButtonText": "提交"
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Select/SelectTree.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<span class="@AppendClassName"><i class="@DropdownIcon"></i></span>
</div>
<div class="dropdown-menu">
<TreeView TItem="TValue" Items="@Items" ShowIcon="ShowIcon"
<TreeView TItem="TValue" Items="@Items" ShowIcon="ShowIcon" @ref="_tv"
OnTreeItemClick="OnItemClick" ModelEqualityComparer="@ModelEqualityComparer"
ShowSearch="ShowSearch" ShowResetSearchButton="ShowResetSearchButton"
CanExpandWhenDisabled="CanExpandWhenDisabled"
Expand Down
9 changes: 7 additions & 2 deletions src/BootstrapBlazor/Components/Select/SelectTree.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ public partial class SelectTree<TValue> : IModelEqualityComparer<TValue>
/// </summary>
[Parameter]
[NotNull]
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
public List<TreeViewItem<TValue>>? Items { get; set; }

/// <summary>
Expand Down Expand Up @@ -168,6 +166,7 @@ public partial class SelectTree<TValue> : IModelEqualityComparer<TValue>
private TreeViewItem<TValue>? _selectedItem;
private List<TreeViewItem<TValue>>? _itemCache;
private List<TreeViewItem<TValue>>? _expandedItemsCache;
private TreeView<TValue> _tv = default!;

private string? SelectTreeCustomClassString => CssBuilder.Default(CustomClassString)
.AddClass("select-tree", IsPopover)
Expand Down Expand Up @@ -235,6 +234,12 @@ private void OnChange(ChangeEventArgs args)
if (args.Value is string v)
{
CurrentValueAsString = v;

// 选中节点更改为当前值
if(_tv != null)
{
_tv.SetActiveItem(Value);
}
}
}

Expand Down
Loading