AutoClose
Use the AutoClose property to allow users to close the overlay by clicking anywhere on it.
@inject ISnackbar Snackbar <MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OpenOverlay">Show overlay</MudButton> <MudOverlay @bind-Visible="_visible" DarkBackground AutoClose="true" OnClosed="OnOverlayClosed" />
@code { private bool _visible; public void OpenOverlay() { _visible = true; StateHasChanged(); } public void OnOverlayClosed() { Snackbar.Add("Random message", Severity.Normal); } }
Absolute
The overlay can be contained inside its parent by setting the Absolute property along with the relative class (or CSS position: relative style).
<MudPaper Class="pa-8" Style="height: 300px; position: relative;"> <MudButton Variant="Variant.Filled" Color="Color.Secondary" OnClick="@(e => ToggleOverlay(true))">Show overlay</MudButton> <MudOverlay Visible="visible" DarkBackground="true" Absolute="true"> <MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(e => ToggleOverlay(false))">Hide overlay</MudButton> </MudOverlay> </MudPaper>
@code { private bool visible; public void ToggleOverlay(bool value) { visible = value; } }