Blazored / Modal

A powerful and customizable modal implementation for Blazor applications.
https://blazored.github.io/Modal/
MIT License
764 stars 184 forks source link

[Feature Request] Add OnBeforeClose hook. #540

Open MarcelRoozekrans opened 7 months ago

MarcelRoozekrans commented 7 months ago

Is your feature request related to a problem? Please describe. We have an application where we want to execute code at then end of the dialog. The logic that now closes first the dialog and adfter that we can execute some custom logic.

Describe the solution you'd like A OnBeforeClosing hook so we can execute code that runs behind the opened dialog.

Describe alternatives you've considered There are none I can think of.

Additional context I'll open a PR that implements this feature.

chrissainty commented 4 months ago

Hey @MarcelRoozekrans, thanks for your request. I'm just trying to understand the use case. When opening a modal it looks something like this:

var moviesModal = Modal.Show<Movies>("My Movies");
var result = await moviesModal.Result;

if (result.Cancelled)
{
    Console.WriteLine("Modal was cancelled");
}
else if (result.Confirmed)
{
    Console.WriteLine("Modal was closed");
}

What benefit would a OnBeforeClosing hook give versus just putting code that needs to run after the modal closes somewhere after the line that awaits the modal result?

MarcelRoozekrans commented 4 months ago

Hi @chrissainty, Thanks for the response !

This proposed solution is that you can execute an action before the dialog is closed. With your example above the dialog is closed first and the afterwards de logic is executed.

We need this because when the modal is closed I want to directly update the parent page. The actions we do in de OnBeforeClose take significant amount of time and there for the parent page has a ugly redraw with the new state way after the dialog is closed.

oliv0533 commented 3 months ago

I'm in full support for this feature, with a small addition.

I'm currently working on an application where we need to show a "Are you sure you want to close this"-modal in case any changes has been made inside a that has been commanded to close. Currently we have to disable closing this modal by the x in the top or clicking outside. Then we add our own close button to the modal window and trigger the "Are you sure" modal using that button.

We would love to allow the the user to close the modal by clicking outside, but to do that we need this hook to run our own modal code first.

The addition we would love is the ability to stop the closing of the modal using this hook. Maybe this hook could return a bool or something, that could stop the closing process, so any changes inside the modal isn't disposed of.

sskieller commented 2 months ago

@chrissainty Is it a possibility we can help with this issue and get it prioritized? :)