Skip to content

Commit 2afd487

Browse files
committed
feat: Trigger OnCancel and OnClose event on dialog
1 parent c37455b commit 2afd487

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad
1515

1616
- Support for custom service provider factories (`IServiceProviderFactory<TContainerBuilder>`). This enables the use of Autofac and other frameworks for dependency injection like on real-world ASP.NET Core / Blazor projects. By [@inf9144](https://github.com/inf9144).
1717

18+
- Ability to raise the `oncancel` and `onclose` event, that was introduced with .NET 8.
19+
1820
## [1.23.9] - 2023-09-06
1921

2022
### Fixed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using AngleSharp.Dom;
2+
3+
#if NET8_0_OR_GREATER
4+
namespace Bunit;
5+
6+
/// <summary>
7+
/// Dialog helper events.
8+
/// </summary>
9+
public static class DialogEventDispatchExtensions
10+
{
11+
/// <summary>
12+
/// Raises the <c>@oncancel</c> event on <paramref name="element"/>, passing an empty (<see cref="EventArgs.Empty"/>).
13+
/// </summary>
14+
public static void Cancel(this IElement element) => _ = CancelAsync(element);
15+
16+
/// <summary>
17+
/// Raises the <c>@oncancel</c> event on <paramref name="element"/>, passing an empty (<see cref="EventArgs.Empty"/>).
18+
/// </summary>
19+
public static Task CancelAsync(this IElement element) => element.TriggerEventAsync("oncancel", EventArgs.Empty);
20+
21+
/// <summary>
22+
/// Raises the <c>@onclose</c> event on <paramref name="element"/>, passing an empty (<see cref="EventArgs.Empty"/>.
23+
/// </summary>
24+
public static void Close(this IElement element) => _ = CloseAsync(element);
25+
26+
/// <summary>
27+
/// Raises the <c>@onclose</c> event on <paramref name="element"/>, passing an empty (<see cref="EventArgs.Empty"/>.
28+
/// </summary>
29+
public static Task CloseAsync(this IElement element) => element.TriggerEventAsync("onclose", EventArgs.Empty);
30+
}
31+
#endif

0 commit comments

Comments
 (0)