Skip to content

Commit 12ea8d8

Browse files
authored
feat(SelectTree): add auto active value function (#6691)
* refactor: 文档格式化 * feat: 增加选中节点逻辑 * doc: 更新可编辑文档 * refactor: 精简代码
1 parent c986015 commit 12ea8d8

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

src/BootstrapBlazor.Server/Components/Samples/SelectTrees.razor

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050

5151
<DemoBlock Title="@Localizer["SelectTreesEditTitle"]"
5252
Introduction="@Localizer["SelectTreesEditIntro"]"
53-
Name="Edit">
53+
Name="IsEditable">
54+
<section ignore>
55+
<div>@((MarkupString)Localizer["SelectTreesEditDesc"].Value)</div>
56+
</section>
5457
<div class="row g-3">
5558
<div class="col-12 col-sm-6">
5659
<SelectTree Items="EditItems" @bind-Value="@Value" IsEditable="true"></SelectTree>

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4893,6 +4893,7 @@
48934893
"SelectTreesClientValidationIntro": "validate the value when submit the form. Inside <code>ValidateForm</code>",
48944894
"SelectTreesEditTitle": "Edit",
48954895
"SelectTreesEditIntro": "By setting <code>IsEditable=\"true\"</code> you can edit the input textbox",
4896+
"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",
48964897
"SelectTreesIsPopoverTitle": "IsPopover",
48974898
"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>",
48984899
"SelectTreesClientValidationButtonText": "Submit"

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4894,6 +4894,7 @@
48944894
"SelectTreesClientValidationIntro": "组件内置 <code>ValidateForm</code> 可设置验证规则",
48954895
"SelectTreesEditTitle": "可输入",
48964896
"SelectTreesEditIntro": "通过设置 <code>IsEditable=\"true\"</code> 可设置下拉框选择后文本框可输入",
4897+
"SelectTreesEditDesc": "设置 <code>IsEditable=\"true\"</code> 后,文本框显示的内容为 <code>TreeView</code> 选中节点的 <code>Value</code> 值,输入值可以不在 <code>Items</code> 集合中",
48974898
"SelectTreesIsPopoverTitle": "悬浮弹窗",
48984899
"SelectTreesIsPopoverIntro": "通过设置 <code>IsPopover</code> 参数,组件使用 <code>popover</code> 渲染 <code>UI</code> 防止由于父容器设置 <code>overflow: hidden;</code> 使弹窗无法显示问题",
48994900
"SelectTreesClientValidationButtonText": "提交"

src/BootstrapBlazor/Components/Select/SelectTree.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<span class="@AppendClassName"><i class="@DropdownIcon"></i></span>
2121
</div>
2222
<div class="dropdown-menu">
23-
<TreeView TItem="TValue" Items="@Items" ShowIcon="ShowIcon"
23+
<TreeView TItem="TValue" Items="@Items" ShowIcon="ShowIcon" @ref="_tv"
2424
OnTreeItemClick="OnItemClick" ModelEqualityComparer="@ModelEqualityComparer"
2525
ShowSearch="ShowSearch" ShowResetSearchButton="ShowResetSearchButton"
2626
CanExpandWhenDisabled="CanExpandWhenDisabled"

src/BootstrapBlazor/Components/Select/SelectTree.razor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ public partial class SelectTree<TValue> : IModelEqualityComparer<TValue>
6868
/// </summary>
6969
[Parameter]
7070
[NotNull]
71-
#if NET6_0_OR_GREATER
7271
[EditorRequired]
73-
#endif
7472
public List<TreeViewItem<TValue>>? Items { get; set; }
7573

7674
/// <summary>
@@ -168,6 +166,7 @@ public partial class SelectTree<TValue> : IModelEqualityComparer<TValue>
168166
private TreeViewItem<TValue>? _selectedItem;
169167
private List<TreeViewItem<TValue>>? _itemCache;
170168
private List<TreeViewItem<TValue>>? _expandedItemsCache;
169+
private TreeView<TValue> _tv = default!;
171170

172171
private string? SelectTreeCustomClassString => CssBuilder.Default(CustomClassString)
173172
.AddClass("select-tree", IsPopover)
@@ -235,6 +234,9 @@ private void OnChange(ChangeEventArgs args)
235234
if (args.Value is string v)
236235
{
237236
CurrentValueAsString = v;
237+
238+
// 选中节点更改为当前值
239+
_tv.SetActiveItem(Value);
238240
}
239241
}
240242

0 commit comments

Comments
 (0)