Skip to content
Merged
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
42 changes: 24 additions & 18 deletions src/BootstrapBlazor/Components/Select/Select.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,18 @@ public partial class Select<TValue> : ISelect, ILookup
public bool DisableItemChangedWhenFirstRender { get; set; }

/// <summary>
/// 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 则改变选中项的值;否则选中项的值不变。
/// <para>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.</para>
/// </summary>
[Parameter]
public Func<SelectedItem, Task<bool>>? OnBeforeSelectedItemChange { get; set; }

/// <summary>
/// Gets or sets whether to show the Swal confirmation popup when <see cref="OnBeforeSelectedItemChange"/> returns true. Default is true.
/// 获得/设置 是否显示 Swal 确认弹窗
/// Gets or sets whether to show the Swal confirmation popup. Default is false.
/// 获得/设置 是否显示 Swal 确认弹窗 默认值 为 false
/// </summary>
[Parameter]
public bool ShowSwal { get; set; } = true;
public bool ShowSwal { get; set; }

/// <summary>
/// Gets or sets the callback method when the selected item changes.
Expand Down Expand Up @@ -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;
Expand Down