Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 19 additions & 0 deletions src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ namespace BootstrapBlazor.Components;
/// </summary>
public static class DialogServiceExtensions
{
/// <summary>
/// 弹出带结果的对话框
/// </summary>
/// <param name="service">DialogService 服务实例</param>
/// <param name="title">对话框标题,优先级高于 <see cref="DialogOption.Title"/></param>
/// <param name="parameters">TCom 组件所需要的参数集合</param>
/// <param name="dialog">指定弹窗组件 默认为 null 使用 <see cref="BootstrapBlazorRoot"/> 组件内置弹窗组件</param>
public static Task Show<TComponent>(this DialogService service, string title, IDictionary<string, object?>? parameters = null, Dialog? dialog = null) where TComponent : IComponent
{
var option = new DialogOption();
if (!string.IsNullOrEmpty(title))
{
option.Title = title;
}
option.ShowFooter = false;
option.Component = BootstrapDynamicComponent.CreateComponent<TComponent>(parameters);
return service.Show(option, dialog);
}

/// <summary>
/// 弹出搜索对话框
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions test/UnitTest/Components/DialogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ await cut.InvokeAsync(() => dialog.ShowCloseDialog<MockValidateFormDialog>("Clos
}));
await cut.InvokeAsync(() => modal.Instance.CloseCallback());
#endregion

#region Show Extensions Method
await cut.InvokeAsync(() => dialog.Show<MockValidateFormDialog>("Test Title"));
await cut.InvokeAsync(() => modal.Instance.CloseCallback());
#endregion
}

private class MockValidateFormDialog : ComponentBase
Expand Down