6

I am aware of Blazored Modal and this answer, but I do not want to have a specific component just for showing modals (lack of flexibility) and want to implement the code in various components myself.

Here is a very simple code to show a sample modal:

@page "/fetchdata"


<button class="btn btn-primary" @onclick="@(() => { showModal = true; })">Show Dialog!</button>
@if (showModal)
{
<div class="modal-backdrop fade show" tabindex="-1" role="dialog" style="display: block;">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Modal title</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <p>Modal body text goes here.</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary">Save changes</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
}
<hr />

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>


@code {
    bool showModal = false;
}

The code works but there is a problem with opacity: enter image description here

Putting style="opacity:1;" on <div class="modal-dialog" role="document"> also does not resolve the problem (though giving the opacity, values lower than 1 makes it more transparent!)

What is the cause of the problem and how it can be fixed?

wiki
  • 1,877
  • 2
  • 31
  • 47
  • Right click the dialog element and inspect it. Look at the calculated style for the opacity and it will tell you which part of your css is making it semitransparent. – Peter Morris Jun 13 '20 at 16:53
  • You can use this Nuget package: https://www.nuget.org/packages/Majorsoft.Blazor.Components.Modal/ It supports backdrop and animation as well... Docs: https://github.com/majorimi/blazor-components/blob/master/.github/docs/Modal.md – Major Nov 16 '20 at 19:30

1 Answers1

5

Don't use modal-backdrop directly. Use simply modal. modal-backdrop is what's applied by the framework to the background content.

Rkand
  • 471
  • 2
  • 9
  • Your suggestion solves the opacity problem of the modal window but how I can make the background darker then (modal-backdrop effect)? – wiki Jun 13 '20 at 18:49
  • 2
    but an extra div for backdrop http://blog.ppedv.de/post/Boostrap-Modal-Dialog-fur-Blazor – HannesPreishuber Jun 14 '20 at 09:34