Skip to content

Commit

Permalink
feat: Trigger OnCancel and OnClose event on dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Oct 13, 2023
1 parent c37455b commit 2afd487
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad

- 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).

- Ability to raise the `oncancel` and `onclose` event, that was introduced with .NET 8.

## [1.23.9] - 2023-09-06

### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using AngleSharp.Dom;

#if NET8_0_OR_GREATER
namespace Bunit;

/// <summary>
/// Dialog helper events.
/// </summary>
public static class DialogEventDispatchExtensions
{
/// <summary>
/// Raises the <c>@oncancel</c> event on <paramref name="element"/>, passing an empty (<see cref="EventArgs.Empty"/>).
/// </summary>
public static void Cancel(this IElement element) => _ = CancelAsync(element);

/// <summary>
/// Raises the <c>@oncancel</c> event on <paramref name="element"/>, passing an empty (<see cref="EventArgs.Empty"/>).
/// </summary>
public static Task CancelAsync(this IElement element) => element.TriggerEventAsync("oncancel", EventArgs.Empty);

/// <summary>
/// Raises the <c>@onclose</c> event on <paramref name="element"/>, passing an empty (<see cref="EventArgs.Empty"/>.
/// </summary>
public static void Close(this IElement element) => _ = CloseAsync(element);

/// <summary>
/// Raises the <c>@onclose</c> event on <paramref name="element"/>, passing an empty (<see cref="EventArgs.Empty"/>.
/// </summary>
public static Task CloseAsync(this IElement element) => element.TriggerEventAsync("onclose", EventArgs.Empty);
}
#endif

0 comments on commit 2afd487

Please sign in to comment.