Skip to content

Commit 6dcf51c

Browse files
committed
Mask增加OnCloseAsync回调
1 parent 948a9b9 commit 6dcf51c

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div style="background-color: #ffffff" class="row">
2+
<div class="col-12">
3+
<h3>MaskDemo</h3>
4+
</div>
5+
<div class="col-12">
6+
<Button Text="Close" OnClick="() => { OnCloseAsync?.Invoke(); }"></Button>
7+
</div>
8+
</div>
9+
@code {
10+
[CascadingParameter]
11+
private Func<Task>? OnCloseAsync { get; set; }
12+
}

src/BootstrapBlazor.Server/Components/Samples/Masks.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@
2727
<Mask @ref="CustomMask1"></Mask>
2828
<Mask @ref="CustomMask2"></Mask>
2929
</DemoBlock>
30+
31+
<DemoBlock Title="代码关闭弹窗">
32+
<Button Text="Show" OnClick="ShowCloseMask"></Button>
33+
</DemoBlock>

src/BootstrapBlazor.Server/Components/Samples/Masks.razor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,12 @@ await MaskService.Show(new MaskOption()
5656
await MaskService.Close(CustomMask1);
5757
await MaskService.Close(CustomMask2);
5858
}
59+
60+
private async Task ShowCloseMask()
61+
{
62+
await MaskService.Show(new MaskOption()
63+
{
64+
ChildContent = BootstrapDynamicComponent.CreateComponent<MaskDemo>().Render()
65+
});
66+
}
5967
}

src/BootstrapBlazor/Components/Mask/Mask.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
@if (_options is { ChildContent: not null })
1010
{
1111
<div class="bb-mask-content">
12-
@_options.ChildContent
12+
<CascadingValue Value="CloseAsync" IsFixed="true">
13+
@_options.ChildContent
14+
</CascadingValue>
1315
</div>
1416
}
1517
</div>

src/BootstrapBlazor/Components/Mask/Mask.razor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ private Task Show(MaskOption? option)
5858
StateHasChanged();
5959
return Task.CompletedTask;
6060
}
61+
62+
private Task CloseAsync()
63+
{
64+
return Show(null);
65+
}
6166
}

0 commit comments

Comments
 (0)