Blazored / Modal

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

Fix bug with BlazoredModalInstance SetTitle with nested modals #572

Open zootius opened 3 months ago

zootius commented 3 months ago

I have found a problem with raising nested modals on a page, specifically where the title of the "parent" modal has been set with SetTitle().

You can reproduce the problem by trying the following in your Blazored.Modal BlazorWebAssembly sample project:

protected override void OnInitialized() { BlazoredModal.SetTitle("First Modal v2"); }

Now do this:

  1. Run the sample WASM
  2. Visit the MultipleModals page, and click the "Show Modal" button
  3. See that the First Modal Title has been set to "First Modal v2" correctly
  4. Click the "Yes" button on the First Modal
  5. Click the "Cancel" button on the Second Modal
  6. You will see that the First Modal has now lost its "First Modal v2" title, and fallen back to the original title of "First Modal".

I believe this is due to the original Title parameter being automatically reset by Blazor's RenderFragment mechanism.

So, my fix in this pull request is to use a private _title variable in the modal instance, which is written to once only by the Parameter, and subsequently only modified by use of the SetTitle method. Please let me know what you think.

Cheers, James