[Bug] DisableBackgroundCancel doesn't seem to work in version 2.3.0
See original GitHub issueDescribe the bug Setting DisableBackgroundCancel to True doesn’t seem to have any effect. I can still close the Modal by pressing in the background.
I’m using version 2.3.0
To Reproduce
My code to open:
Modal.Show("My App", typeof(MyCustomComponent), parameters, new ModalOptions() { DisableBackgroundCancel = true });
It’s worth noting that I’m using my own BlazorStandardModal from whenever that was a thing in the Repository.
BlazorStandardModal.razor
@inherits Blazored.Modal.BlazoredModalBase
<div class="blazored-modal-container @(IsVisible ? "blazored-modal-active" : string.Empty)">
<div class="blazored-modal-overlay" @onclick="@(() => ModalService.Cancel())"></div>
<div class="blazored-modal">
<div class="blazored-modal-header">
<img src="/assets/img/logo.png" height="60" />
<h3 class="blazored-modal-title">@Title</h3>
<button type="button" class="blazored-modal-close" @onclick="@(() => ModalService.Cancel())">
<span>×</span>
</button>
</div>
<div class="blazored-modal-content">
<CascadingValue Value="@Parameters">
@Content
</CascadingValue>
</div>
</div>
</div>
Expected behavior Expectation would be that it doesn’t close the modal when clicking in the background.
Hosting Model (is this issue happening with a certain hosting model?):
- Blazor Server
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
No results found
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 FreeTop 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
Top GitHub Comments
Ahh okay that makes sense then.
We only really use Modals as Confirmation boxes for stuff like “Are you sure you wanna do this?” type of thing, and in the 150 places we’re using it there is no issues.
Funny enough, I solved the original issue just now by using the following code:
<div class="blazored-modal-overlay" @onclick="@(() => { if (!ComponentDisableBackgroundCancel) ModalService.Cancel(); })"></div>
Where the difference is that using ComponentDisableBackgroundCancel aswell as testing with False, apparently works like if DisableBackgroundCancel was set to true in ModalOptions.A bit hacky, but I guess it works 😄
I’ll put it on my todo to actually upgrade to the latest, but that’s alot of work so that won’t be happening right now then 😄 But thanks for helping me out! I appreciate it!
We do have that overload, it’s just the order is
Show(ComponentType, Title, Parameters, Options)
. Unfortunately we wouldn’t want to just change the order again. So we can’t help with this I’m afraid.I’m not sure if you’ve seen the latest changes but there are further breaks to the old API as well. We no longer have the
Closed
event and we have moved to modal instances which you can await the result of which is a much nicer programming model to work with. So there are probably more changes you would have to make. If there is no benefit to your app, then I understand not wanting to change anything.