question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modal closing issue

See original GitHub issue

Describe the bug

If I have a modal displayed on my current page & an event is triggered in my application causing a redirection to another page, the modal is still displayed even though the _visible boolean is set to false & DestroyOnClose is set to modal, the dispose method is correctly called & boolean is correctly set to false. Small example is provided below.

Steps to reproduce (please include code)

Modal.razor :

@implements IDisposable


<Modal DestroyOnClose Style="width:50%;" Visible="_showPasswordModal" OnCancel="()=>_showPasswordModal=false" >
                <TitleTemplate>
                    <h3 >test</h3>
                </TitleTemplate>
 </Modal >

   
@code{
public override void Dispose(){
    _showPasswordModal=false;
     base.Dispose();
}
} 

App.razor

private Timer? _timerRedirect;
protected async override Task OnInitializedAsync()
 {
  
     _timerRedirect = new Timer( 2000 );
     _timerRedirect.Elapsed += UpdateTimerRedirect;
   
     _timerRedirect.AutoReset = false;
 
     await base.OnInitializedAsync();

 }
     
private async void UpdateTimerRedirect( Object? source, ElapsedEventArgs e )
 {

             Navigation.NavigateTo( "/");

 }

Exceptions (if any)

None

Further technical details

  • AntDesign Nuget Package version 15.4
  • Include the output of dotnet --info .net 6/7

Issue Analytics

  • State:open
  • Created 2 months ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
zxyao145commented, Aug 9, 2023

@quirynen Get it, Modal cannot be wrapped by HTML native elements, because the lifecycle of HTML native elements is not managed by Blazor.

If you have a Div.razor component below (no need to implement IDisposable):

@ChildContent

@code
{
    [Parameter]
    public RenderFragment? ChildContent { get; set; }
}

This will work well:

<Div>
    <Modal DestroyOnClose Style="width:50%;" Visible="_showPasswordModal" OnCancel="()=>_showPasswordModal=false">
        <TitleTemplate>
            <h3>test</h3>
        </TitleTemplate>
        <ChildContent>
            <a href="/counter">link</a>
        </ChildContent>
    </Modal>
</Div>

In fact, wrapping Modal with div is meaningless, because Modal will be extracted into the body after being rendered.

image

Next, I will try to improve this issue. Before that, please do not use the native HTML native wrapping Modal component.

0reactions
quirynencommented, Aug 9, 2023

Ok thanks for the feedback, maybe it’d be a good idea to mention it in the documentation if someone encountered this issue in the future

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap close modal not working
I have two button here that are being used to close the modal. The first is the close icon and the other one...
Read more >
Closing the task modal, reloads the page and opens...
Closing the task modal, reloads the page, and opens the modal again. I have no way to access the board/dashboard without going to...
Read more >
Problems with closing modals - Animations & Interactions
It is a super easy fix - you just have to uncheck the “loop” button on your “open-modal-accomodation” interaction.
Read more >
Closing second modal closes the first after upgrade to 6.1.0
If there are multiple modals on screen without an id value, then closing one causes all of them to close. I believe in...
Read more >
Reasons to close a Modal in Outsystems
Im having issues with modals in traditional web. Im going to describe my issue since I am more of a reactive guy. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found