Showing a modal dialog in blazor client

Viewed 6436

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?

1 Answers

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

Related