Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with BlazoredModalInstance SetTitle with nested modals #572

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zootius
Copy link
Contributor

@zootius zootius commented Mar 18, 2024

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:

  • In MultipleModals.razor , see how you are opening a first Modal : Modal.Show<YesNoPrompt>("First Modal");
  • Modify the YesNoPrompt component, to change its own Modal Title :

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

@zootius zootius changed the title Fix bug with BlazoredModalInstance Title Fix bug with BlazoredModalInstance SetTitle with nested modals Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant