[PR #2065] [CLOSED] Support for intercepting dialog close actions #3060

Open
opened 2026-01-29 18:21:44 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/radzenhq/radzen-blazor/pull/2065
Author: @JvanderStad
Created: 3/29/2025
Status: Closed

Base: masterHead: development/jeffrey/dialog-beforeclose-callback


📝 Commits (5)

  • 0de51a4 Refactor DialogService and enhance dialog closing logic
  • 7ae2a0d Add tests for dialog close behavior and improve code
  • 1c2bc09 refactor(dialog): rename close callback methods
  • 3e1b0bc Merge branch 'radzenhq:master' into development/jeffrey/dialog-beforeclose-callback
  • 932d382 Merge branches 'development/jeffrey/dialog-beforeclose-callback' and 'development/jeffrey/dialog-beforeclose-callback' of https://github.com/Hybrid-SaaS/radzen-blazor into development/jeffrey/dialog-beforeclose-callback

📊 Changes

5 files changed (+340 additions, -31 deletions)

View changed files

Radzen.Blazor.Tests/DialogContainerTests.cs (+206 -0)
📝 Radzen.Blazor/DialogService.cs (+37 -24)
📝 Radzen.Blazor/Rendering/DialogContainer.razor (+48 -7)
RadzenBlazorDemos/Pages/DialogBeforeCloseHandler.razor (+31 -0)
📝 RadzenBlazorDemos/Pages/DialogPage.razor (+18 -0)

📄 Description

Support for intercepting dialog close actions

This PR introduces robust support for handling dialog close events with the ability to intercept and optionally cancel dialog closure initiated from the UI, using newly added before-close callbacks.

👁️ Demo

before-close

Key Features

  • Before-close callbacks added

    • DialogOptions now supports two optional callbacks:
      • OnBeforeDialogClose: a synchronous function (Dialog) => bool to intercept the close request.
      • OnBeforeDialogCloseAsync: an asynchronous function (Dialog) => Task<bool> that supports async operations (e.g. saving state, fetching confirmation).
    • When either of these callbacks is provided, they are invoked before a dialog is closed via the UI (e.g. escape key, close button).
    • Returning false from either callback cancels the close operation.
    • These callbacks are not triggered when the dialog is closed programmatically via DialogService.Close(...).
  • Asynchronous close support in DialogContainer.razor

    • Updated to use await CloseAsync() logic internally to honor the async lifecycle of the before-close callbacks.

Additional Enhancements

  • Test coverage

    • Added DialogBeforeCloseTests in DialogContainerTests.cs to validate correct behavior of both sync and async before-close scenarios.
    • Refactored the visibility of CloseAsync and Service to internal to support testing.
    • Updated DialogService.Dispose() to safely unsubscribe from UriHelper.LocationChanged.
  • Demo and documentation

    • New example component: DialogBeforeCloseHandler.razor demonstrates both sync and async confirmation before closing.
    • Enhanced DialogPage.razor with practical usage patterns for the before-close feature.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/radzenhq/radzen-blazor/pull/2065 **Author:** [@JvanderStad](https://github.com/JvanderStad) **Created:** 3/29/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `development/jeffrey/dialog-beforeclose-callback` --- ### 📝 Commits (5) - [`0de51a4`](https://github.com/radzenhq/radzen-blazor/commit/0de51a4964172efcaae86a5e8c6962915ab65172) Refactor DialogService and enhance dialog closing logic - [`7ae2a0d`](https://github.com/radzenhq/radzen-blazor/commit/7ae2a0d97f9231e82801085b44e88f40ea5e7415) Add tests for dialog close behavior and improve code - [`1c2bc09`](https://github.com/radzenhq/radzen-blazor/commit/1c2bc09f6ff00b959fdb46f9468638547d90e23a) refactor(dialog): rename close callback methods - [`3e1b0bc`](https://github.com/radzenhq/radzen-blazor/commit/3e1b0bcfd46748bc5f7ac13324df0a23284367c5) Merge branch 'radzenhq:master' into development/jeffrey/dialog-beforeclose-callback - [`932d382`](https://github.com/radzenhq/radzen-blazor/commit/932d3826d8f5d38228c18b649d85c91c91a20dd2) Merge branches 'development/jeffrey/dialog-beforeclose-callback' and 'development/jeffrey/dialog-beforeclose-callback' of https://github.com/Hybrid-SaaS/radzen-blazor into development/jeffrey/dialog-beforeclose-callback ### 📊 Changes **5 files changed** (+340 additions, -31 deletions) <details> <summary>View changed files</summary> ➕ `Radzen.Blazor.Tests/DialogContainerTests.cs` (+206 -0) 📝 `Radzen.Blazor/DialogService.cs` (+37 -24) 📝 `Radzen.Blazor/Rendering/DialogContainer.razor` (+48 -7) ➕ `RadzenBlazorDemos/Pages/DialogBeforeCloseHandler.razor` (+31 -0) 📝 `RadzenBlazorDemos/Pages/DialogPage.razor` (+18 -0) </details> ### 📄 Description # Support for intercepting dialog close actions This PR introduces robust support for handling dialog close events with the ability to **intercept and optionally cancel dialog closure initiated from the UI**, using newly added before-close callbacks. ## 👁️ Demo ![before-close](https://github.com/user-attachments/assets/41577179-75de-47ca-9b67-8dd1c9e7c206) ## ✨ Key Features - **Before-close callbacks added** - `DialogOptions` now supports two optional callbacks: - `OnBeforeDialogClose`: a synchronous function `(Dialog) => bool` to intercept the close request. - `OnBeforeDialogCloseAsync`: an asynchronous function `(Dialog) => Task<bool>` that supports async operations (e.g. saving state, fetching confirmation). - When either of these callbacks is provided, they are invoked **before a dialog is closed via the UI (e.g. escape key, close button)**. - Returning `false` from either callback cancels the close operation. - These callbacks are **not triggered** when the dialog is closed programmatically via `DialogService.Close(...)`. - **Asynchronous close support in `DialogContainer.razor`** - Updated to use `await CloseAsync()` logic internally to honor the async lifecycle of the before-close callbacks. ## ✅ Additional Enhancements - **Test coverage** - Added `DialogBeforeCloseTests` in `DialogContainerTests.cs` to validate correct behavior of both sync and async before-close scenarios. - Refactored the visibility of `CloseAsync` and `Service` to `internal` to support testing. - Updated `DialogService.Dispose()` to safely unsubscribe from `UriHelper.LocationChanged`. - **Demo and documentation** - New example component: `DialogBeforeCloseHandler.razor` demonstrates both sync and async confirmation before closing. - Enhanced `DialogPage.razor` with practical usage patterns for the before-close feature. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 18:21:44 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#3060