Modal closing issue
See original GitHub issueDescribe 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:
- Created 2 months ago
- Comments:8 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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):This will work well:
In fact, wrapping Modal with
div
is meaningless, because Modal will be extracted into the body after being rendered.Next, I will try to improve this issue. Before that, please do not use the native HTML native wrapping Modal component.
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