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.

[Bug] DisableBackgroundCancel doesn't seem to work in version 2.3.0

See original GitHub issue

Describe 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>&times;</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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kevinjpetersencommented, Mar 27, 2020

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!

0reactions
chrissaintycommented, Mar 27, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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