Skip to content

Commit 75553b8

Browse files
authored
feat(Select): redesign OnBeforeSelectedItemChange logic (#6199)
* refactor: 重构 ShowSwal 逻辑 * refactor: 更改 ShowSwal 默认值
1 parent 7ba4e74 commit 75553b8

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,18 @@ public partial class Select<TValue> : ISelect, ILookup
5252
public bool DisableItemChangedWhenFirstRender { get; set; }
5353

5454
/// <summary>
55-
/// 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.
55+
/// 获取/设置 选中项改变前的回调方法。返回 true 则改变选中项的值;否则选中项的值不变。
56+
/// <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>
5657
/// </summary>
5758
[Parameter]
5859
public Func<SelectedItem, Task<bool>>? OnBeforeSelectedItemChange { get; set; }
5960

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

6768
/// <summary>
6869
/// Gets or sets the callback method when the selected item changes.
@@ -342,26 +343,31 @@ public async Task ConfirmSelectedItem(int index)
342343
private async Task OnClickItem(SelectedItem item)
343344
{
344345
var ret = true;
346+
347+
// 自定义回调方法 OnBeforeSelectedItemChange 返回 false 时不修改选中项
345348
if (OnBeforeSelectedItemChange != null)
346349
{
347350
ret = await OnBeforeSelectedItemChange(item);
348-
if (ret && ShowSwal)
351+
}
352+
353+
// 如果 ShowSwal 为 true 且 则显示 Swal 确认弹窗,通过确认弹窗返回值决定是否修改选中项
354+
if (ret && ShowSwal)
355+
{
356+
var option = new SwalOption()
357+
{
358+
Category = SwalCategory,
359+
Title = SwalTitle,
360+
Content = SwalContent
361+
};
362+
if (!string.IsNullOrEmpty(SwalFooter))
349363
{
350-
// Return true to show modal
351-
var option = new SwalOption()
352-
{
353-
Category = SwalCategory,
354-
Title = SwalTitle,
355-
Content = SwalContent
356-
};
357-
if (!string.IsNullOrEmpty(SwalFooter))
358-
{
359-
option.ShowFooter = true;
360-
option.FooterTemplate = builder => builder.AddContent(0, SwalFooter);
361-
}
362-
ret = await SwalService.ShowModal(option);
364+
option.ShowFooter = true;
365+
option.FooterTemplate = builder => builder.AddContent(0, SwalFooter);
363366
}
367+
ret = await SwalService.ShowModal(option);
364368
}
369+
370+
// 如果 ret 为 true 则修改选中项
365371
if (ret)
366372
{
367373
_defaultVirtualizedItemText = item.Text;

0 commit comments

Comments
 (0)