diff --git a/src/BootstrapBlazor/Components/Select/Select.razor.cs b/src/BootstrapBlazor/Components/Select/Select.razor.cs index 5144a13b7ca..9756f754d56 100644 --- a/src/BootstrapBlazor/Components/Select/Select.razor.cs +++ b/src/BootstrapBlazor/Components/Select/Select.razor.cs @@ -52,17 +52,18 @@ public partial class Select : ISelect, ILookup public bool DisableItemChangedWhenFirstRender { get; set; } /// - /// 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. + /// 获取/设置 选中项改变前的回调方法。返回 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; } /// - /// Gets or sets whether to show the Swal confirmation popup when returns true. Default is true. - /// 获得/设置 是否显示 Swal 确认弹窗 + /// Gets or sets whether to show the Swal confirmation popup. Default is false. + /// 获得/设置 是否显示 Swal 确认弹窗 默认值 为 false /// [Parameter] - public bool ShowSwal { get; set; } = true; + public bool ShowSwal { get; set; } /// /// Gets or sets the callback method when the selected item changes. @@ -342,26 +343,31 @@ public async Task ConfirmSelectedItem(int index) private async Task OnClickItem(SelectedItem item) { var ret = true; + + // 自定义回调方法 OnBeforeSelectedItemChange 返回 false 时不修改选中项 if (OnBeforeSelectedItemChange != null) { ret = await OnBeforeSelectedItemChange(item); - if (ret && ShowSwal) + } + + // 如果 ShowSwal 为 true 且 则显示 Swal 确认弹窗,通过确认弹窗返回值决定是否修改选中项 + if (ret && ShowSwal) + { + var option = new SwalOption() + { + Category = SwalCategory, + Title = SwalTitle, + Content = SwalContent + }; + if (!string.IsNullOrEmpty(SwalFooter)) { - // Return true to show modal - var option = new SwalOption() - { - Category = SwalCategory, - Title = SwalTitle, - Content = SwalContent - }; - if (!string.IsNullOrEmpty(SwalFooter)) - { - option.ShowFooter = true; - option.FooterTemplate = builder => builder.AddContent(0, SwalFooter); - } - ret = await SwalService.ShowModal(option); + option.ShowFooter = true; + option.FooterTemplate = builder => builder.AddContent(0, SwalFooter); } + ret = await SwalService.ShowModal(option); } + + // 如果 ret 为 true 则修改选中项 if (ret) { _defaultVirtualizedItemText = item.Text;