From a7729bc8027b0cc752f0aef35686ccca11a0b5a6 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 15 Mar 2025 11:18:16 +0800 Subject: [PATCH 1/7] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/Selects.razor.cs | 8 ++++++++ src/BootstrapBlazor.Server/Locales/en-US.json | 3 ++- src/BootstrapBlazor.Server/Locales/zh-CN.json | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Server/Components/Samples/Selects.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Selects.razor.cs index 11332afc37b..ae153e5d110 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Selects.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Selects.razor.cs @@ -357,6 +357,14 @@ private AttributeItem[] GetAttributes() => DefaultValue = "false" }, new() + { + Name = "IsFixedSearch", + Description = Localizer["SelectsIsFixedSearch"], + Type = "boolean", + ValueList = "true / false", + DefaultValue = "false" + }, + new() { Name = "IsDisabled", Description = Localizer["SelectsIsDisabled"], diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json index 3636abe6d2b..01f59fabca7 100644 --- a/src/BootstrapBlazor.Server/Locales/en-US.json +++ b/src/BootstrapBlazor.Server/Locales/en-US.json @@ -3194,7 +3194,8 @@ "SelectsGenericDesc": "

Please refer to Design Ideas to understand this feature. In this example, by selecting the drop-down box option, the value obtained is the Foo instance, and the value displayed in the text box on the right is the Address value of the Foo attribute

In this example, the ValueEqualityComparer and CustomKeyAttribute parameters are not set, and the [Key] tag of the Id attribute of Foo is used for equality judgment

", "SelectsOnInputChangedCallback": "Callback method for converting input text into corresponding Value in edit mode", "TextConvertToValueCallback": "Callback method when input text changes in edit mode", - "SelectsIsEditable": "Whether editable" + "SelectsIsEditable": "Whether editable", + "SelectsIsFixedSearch": "Whether fixed the search box" }, "BootstrapBlazor.Server.Components.Samples.Sliders": { "SlidersTitle": "Slider", diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json index d1f1067eeca..b4669c64899 100644 --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json @@ -3194,7 +3194,8 @@ "SelectsGenericDesc": "

请参考 设计思路 理解此功能。本例中通过选择下拉框选项,得到的值为 Foo 实例,右侧文本框内显示值为 Foo 属性 Address

本例中未设置 ValueEqualityComparer 以及 CustomKeyAttribute 参数,使用 Foo 属性 Id[Key] 标签进行相等判定

", "SelectsOnInputChangedCallback": "编辑模式下输入文本转换为对应 Value 回调方法", "TextConvertToValueCallback": "编辑模式下输入文本变化时回调方法", - "SelectsIsEditable": "是否可编辑" + "SelectsIsEditable": "是否可编辑", + "SelectsIsFixedSearch": "是否固定搜索栏" }, "BootstrapBlazor.Server.Components.Samples.Sliders": { "SlidersTitle": "Slider 滑块", From b9c265dfd879ffdab74649610fad15aeeeebacf8 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 15 Mar 2025 11:33:57 +0800 Subject: [PATCH 2/7] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Select/Select.razor.cs | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/src/BootstrapBlazor/Components/Select/Select.razor.cs b/src/BootstrapBlazor/Components/Select/Select.razor.cs index 1fb848e459a..682b5f26af2 100644 --- a/src/BootstrapBlazor/Components/Select/Select.razor.cs +++ b/src/BootstrapBlazor/Components/Select/Select.razor.cs @@ -9,7 +9,7 @@ namespace BootstrapBlazor.Components; /// -/// Select 组件实现类 +/// Select component /// /// public partial class Select : ISelect, ILookup @@ -18,17 +18,11 @@ public partial class Select : ISelect, ILookup [NotNull] private SwalService? SwalService { get; set; } - /// - /// 获得 样式集合 - /// private string? ClassString => CssBuilder.Default("select dropdown") .AddClass("cls", IsClearable) .AddClassFromAttributes(AdditionalAttributes) .Build(); - /// - /// 获得 样式集合 - /// private string? InputClassString => CssBuilder.Default("form-select form-control") .AddClass($"border-{Color.ToDescriptionString()}", Color != Color.None && !IsDisabled && !IsValid.HasValue) .AddClass($"border-success", IsValid.HasValue && IsValid.Value) @@ -44,11 +38,6 @@ public partial class Select : ISelect, ILookup private bool GetClearable() => IsClearable && !IsDisabled && IsNullable(); - /// - /// 设置当前项是否 Active 方法 - /// - /// - /// private string? ActiveItem(SelectedItem item) => CssBuilder.Default("dropdown-item") .AddClass("active", item.Value == CurrentValueAsString) .AddClass("disabled", item.IsDisabled) @@ -59,9 +48,6 @@ public partial class Select : ISelect, ILookup .AddClass("is-fixed", IsFixedSearch) .Build(); - /// - /// 获得 SearchLoadingIcon 图标字符串 - /// private string? SearchLoadingIconString => CssBuilder.Default("icon searching-icon") .AddClass(SearchLoadingIcon) .Build(); @@ -393,9 +379,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender) } } - /// - /// 获得/设置 数据总条目 - /// private int TotalCount { get; set; } private List GetVirtualItems() => [.. FilterBySearchText(GetRowsByItems())]; @@ -503,9 +486,6 @@ public async Task TriggerOnSearch(string searchText) StateHasChanged(); } - /// - /// 下拉框选项点击时调用此方法 - /// private async Task OnClickItem(SelectedItem item) { var ret = true; @@ -547,11 +527,9 @@ private async Task SelectedItemChanged(SelectedItem item) item.Active = true; SelectedItem = item; - // 触发 StateHasChanged _lastSelectedValueString = item.Value; CurrentValueAsString = _lastSelectedValueString; - // 触发 SelectedItemChanged 事件 if (OnSelectedItemChanged != null) { await OnSelectedItemChanged(SelectedItem); From 0139c72b8fb72d821c843db73b77659f8fe6ec96 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 15 Mar 2025 11:38:08 +0800 Subject: [PATCH 3/7] =?UTF-8?q?doc:=20=E6=9B=B4=E6=94=B9=E4=B8=BA=E8=8B=B1?= =?UTF-8?q?=E8=AF=AD=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Select/Select.razor.cs | 102 +++++++++--------- 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/src/BootstrapBlazor/Components/Select/Select.razor.cs b/src/BootstrapBlazor/Components/Select/Select.razor.cs index 682b5f26af2..4634c0862d5 100644 --- a/src/BootstrapBlazor/Components/Select/Select.razor.cs +++ b/src/BootstrapBlazor/Components/Select/Select.razor.cs @@ -57,90 +57,90 @@ public partial class Select : ISelect, ILookup private string? ScrollIntoViewBehaviorString => ScrollIntoViewBehavior == ScrollIntoViewBehavior.Smooth ? null : ScrollIntoViewBehavior.ToDescriptionString(); /// - /// 获得/设置 右侧清除图标 默认 fa-solid fa-angle-up + /// Gets or sets the right-side clear icon. Default is fa-solid fa-angle-up. /// [Parameter] [NotNull] public string? ClearIcon { get; set; } /// - /// 获得/设置 搜索文本发生变化时回调此方法 + /// Gets or sets the callback method when the search text changes. /// [Parameter] public Func>? OnSearchTextChanged { get; set; } /// - /// 获得/设置 是否固定下拉框中的搜索栏 默认 false + /// Gets or sets whether the search bar in the dropdown is fixed. Default is false. /// [Parameter] public bool IsFixedSearch { get; set; } /// - /// 获得/设置 是否可编辑 默认 false + /// Gets or sets whether the select component is editable. Default is false. /// [Parameter] public bool IsEditable { get; set; } /// - /// 获得/设置 选项输入更新后回调方法 默认 null + /// Gets or sets the callback method when the input value changes. Default is null. /// - /// 设置 后生效 + /// Effective when is set. [Parameter] public Func? OnInputChangedCallback { get; set; } /// - /// 获得/设置 是否可清除 默认 false + /// Gets or sets whether the select component is clearable. Default is false. /// [Parameter] public bool IsClearable { get; set; } /// - /// 获得/设置 选项模板支持静态数据 + /// Gets or sets the options template for static data. /// [Parameter] public RenderFragment? Options { get; set; } /// - /// 获得/设置 显示部分模板 默认 null + /// Gets or sets the display template. Default is null. /// [Parameter] public RenderFragment? DisplayTemplate { get; set; } /// - /// 获得/设置 是否开启虚拟滚动 默认 false 未开启 注意:开启虚拟滚动后不支持 参数设置,设置初始值时请设置 + /// Gets or sets whether virtual scrolling is enabled. Default is false. Note: When virtual scrolling is enabled, , , and are not supported. Set when setting initial values. /// [Parameter] public bool IsVirtualize { get; set; } /// - /// 获得/设置 虚拟滚动行高 默认为 33 + /// Gets or sets the row height for virtual scrolling. Default is 33. /// - /// 需要设置 值为 true 时生效 + /// Effective when is set to true. [Parameter] public float RowHeight { get; set; } = 33f; /// - /// 获得/设置 过载阈值数 默认为 4 + /// Gets or sets the overscan count for virtual scrolling. Default is 4. /// - /// 需要设置 值为 true 时生效 + /// Effective when is set to true. [Parameter] public int OverscanCount { get; set; } = 4; /// - /// 获得/设置 默认文本 时生效 默认 null + /// Gets or sets the default text for virtualized items. Default is null. /// - /// 开启 并且通过 提供数据源时,由于渲染时还未调用或者调用后数据集未包含 选项值,此时使用 DefaultText 值渲染 + /// Effective when is enabled and data source is provided via . If the data set does not contain the option value during rendering, the DefaultText value is used. [Parameter] public string? DefaultVirtualizeItemText { get; set; } /// - /// 获得/设置 清除文本内容 OnClear 回调方法 默认 null + /// Gets or sets the callback method when the clear button is clicked. Default is null. /// [Parameter] public Func? OnClearAsync { get; set; } /// - /// 获得/设置 禁止首次加载时触发 OnSelectedItemChanged 回调方法 默认 false + /// Gets or sets whether to disable the OnSelectedItemChanged callback method on first render. Default is false. /// [Parameter] public bool DisableItemChangedWhenFirstRender { get; set; } @@ -149,50 +149,50 @@ public partial class Select : ISelect, ILookup private Virtualize? VirtualizeElement { get; set; } /// - /// 获得/设置 绑定数据集 + /// Gets or sets the bound data set. /// [Parameter] [NotNull] public IEnumerable? Items { get; set; } /// - /// 获得/设置 选项模板 + /// Gets or sets the item template. /// [Parameter] public RenderFragment? ItemTemplate { get; set; } /// - /// 获得/设置 下拉框项目改变前回调委托方法 返回 true 时选项值改变,否则选项值不变 + /// Gets or sets the callback method before the selected item changes. Returns true to change the selected item value; otherwise, the selected item value does not change. /// [Parameter] public Func>? OnBeforeSelectedItemChange { get; set; } /// - /// SelectedItemChanged 回调方法 + /// Gets or sets the callback method when the selected item changes. /// [Parameter] public Func? OnSelectedItemChanged { get; set; } /// - /// 获得/设置 Swal 图标 默认 Question + /// Gets or sets the Swal category. Default is Question. /// [Parameter] public SwalCategory SwalCategory { get; set; } = SwalCategory.Question; /// - /// 获得/设置 Swal 标题 默认 null + /// Gets or sets the Swal title. Default is null. /// [Parameter] public string? SwalTitle { get; set; } /// - /// 获得/设置 Swal 内容 默认 null + /// Gets or sets the Swal content. Default is null. /// [Parameter] public string? SwalContent { get; set; } /// - /// 获得/设置 Footer 默认 null + /// Gets or sets the Swal footer. Default is null. /// [Parameter] public string? SwalFooter { get; set; } @@ -215,6 +215,13 @@ public partial class Select : ISelect, ILookup [Parameter] public object? LookupServiceData { get; set; } + /// + /// Gets or sets the callback method for loading virtualized items. + /// + [Parameter] + [NotNull] + public Func>>? OnQueryAsync { get; set; } + /// /// /// @@ -230,21 +237,17 @@ public partial class Select : ISelect, ILookup private IStringLocalizer>? Localizer { get; set; } /// - /// 获得/设置 服务实例 + /// Gets or sets the injected lookup service instance. /// [Inject] [NotNull] private ILookupService? InjectLookupService { get; set; } /// - /// 获得 input 组件 Id 方法 + /// /// - /// protected override string? RetrieveId() => InputId; - /// - /// 获得/设置 Select 内部 Input 组件 Id - /// private string? InputId => $"{Id}_input"; private string _lastSelectedValueString = string.Empty; @@ -255,9 +258,6 @@ public partial class Select : ISelect, ILookup private ItemsProviderResult _result; - /// - /// 当前选择项实例 - /// private SelectedItem? SelectedItem { get; set; } private List Rows @@ -383,13 +383,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender) private List GetVirtualItems() => [.. FilterBySearchText(GetRowsByItems())]; - /// - /// 虚拟滚动数据加载回调方法 - /// - [Parameter] - [NotNull] - public Func>>? OnQueryAsync { get; set; } - private async ValueTask> LoadItems(ItemsProviderRequest request) { // 有搜索条件时使用原生请求数量 @@ -456,14 +449,13 @@ private bool TryParseSelectItem(string value, [MaybeNullWhen(false)] out TValue /// /// /// - /// protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new { ConfirmMethodCallback = nameof(ConfirmSelectedItem), SearchMethodCallback = nameof(TriggerOnSearch) }); /// - /// 客户端回车回调方法 + /// Confirms the selected item. /// - /// - /// + /// The index of the selected item. + /// A task that represents the asynchronous operation. [JSInvokable] public async Task ConfirmSelectedItem(int index) { @@ -475,10 +467,10 @@ public async Task ConfirmSelectedItem(int index) } /// - /// 客户端搜索栏回调方法 + /// Triggers the search callback method. /// - /// - /// + /// The search text. + /// A task that represents the asynchronous operation. [JSInvokable] public async Task TriggerOnSearch(string searchText) { @@ -486,6 +478,11 @@ public async Task TriggerOnSearch(string searchText) StateHasChanged(); } + /// + /// Handles the click event for a dropdown item. + /// + /// The selected item. + /// A task that represents the asynchronous operation. private async Task OnClickItem(SelectedItem item) { var ret = true; @@ -494,7 +491,7 @@ private async Task OnClickItem(SelectedItem item) ret = await OnBeforeSelectedItemChange(item); if (ret) { - // 返回 True 弹窗提示 + // Return true to show modal var option = new SwalOption() { Category = SwalCategory, @@ -510,7 +507,7 @@ private async Task OnClickItem(SelectedItem item) } else { - // 返回 False 直接运行 + // Return false to proceed ret = true; } } @@ -540,11 +537,10 @@ private async Task SelectedItemChanged(SelectedItem item) /// /// /// - /// public void Add(SelectedItem item) => _children.Add(item); /// - /// 清空搜索栏文本内容 + /// Clears the search text. /// public void ClearSearchText() => SearchText = null; From 738acfc2af3c1f03d1ae9e23b6f1de1352d4c664 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 15 Mar 2025 12:00:29 +0800 Subject: [PATCH 4/7] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E6=90=9C=E7=B4=A2=E6=A0=8F=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Select/Select.razor | 49 ++++++++------- .../Components/Select/Select.razor.cs | 9 ++- .../Components/Select/Select.razor.scss | 61 +++++++++---------- 3 files changed, 61 insertions(+), 58 deletions(-) diff --git a/src/BootstrapBlazor/Components/Select/Select.razor b/src/BootstrapBlazor/Components/Select/Select.razor index b9adcebc2f7..f41bc4f7ff9 100644 --- a/src/BootstrapBlazor/Components/Select/Select.razor +++ b/src/BootstrapBlazor/Components/Select/Select.razor @@ -30,12 +30,15 @@ { } -