Migrating drawer behavior in Blazor
The open/close behavior of NvDrawer follows NvDialog. These changes were
introduced after 3.38; the component parameters, callbacks, methods, and fragments
remain available.
Application writes no longer echo OpenChanged#
Previously, setting Open from your own code also raised OpenChanged. Now
that callback reports the drawer's own transitions: trigger, close button,
Escape, backdrop, swipe, footer Cancel, and ShowAsync() or CloseAsync().
This avoids asynchronous feedback loops under Blazor Server. @bind-Open still
works because application state already contains the value it wrote.
Before: opening work depended on the echo.
<NvDrawer Open="open" OpenChanged="OnOpenChanged" />
@code {
private bool open;
private void OpenDrawer() => open = true;
private void OnOpenChanged(bool value)
{
open = value;
if (value) LoadDrawerData();
}
private void LoadDrawerData() { /* Load the drawer's data. */ }
}
After: run that work where you open the drawer too.
<NvDrawer Open="open" OpenChanged="OnOpenChanged" />
@code {
private bool open;
private void OpenDrawer()
{
open = true;
LoadDrawerData();
}
private void OnOpenChanged(bool value)
{
open = value;
if (value) LoadDrawerData();
}
private void LoadDrawerData() { /* Load the drawer's data. */ }
}
Cancel in a custom footer closes the drawer#
A NvDrawerfooter supplied through FooterSlot now closes an uncontrolled
drawer on Cancel, just like the built-in footer. Previously it only raised
DrawerCanceledEvent, and your callback had to close the drawer. An existing
callback that also closes it is redundant but harmless.
To confirm discarding changes before closing, use Controlled="true". The
application then owns trigger opening and footer Cancel. The close button,
Escape, and backdrop can still close it; add Undismissable="true" when those
must also go through your decision.
@using Microsoft.JSInterop
@inject IJSRuntime JS
<NvButton @onclick="() => open = true">Edit item</NvButton>
<NvDrawer @bind-Open="open" Controlled="true" Undismissable="true">
<HeaderSlot>
<NvDrawerheader Heading="Edit item" />
</HeaderSlot>
<ChildContent>
<p>Changes have not been saved.</p>
</ChildContent>
<FooterSlot>
<NvDrawerfooter CancelLabel="Cancel" DrawerCanceledEvent="TryClose" />
</FooterSlot>
</NvDrawer>
@code {
private bool open;
private async Task TryClose()
{
if (await JS.InvokeAsync<bool>("confirm", "Discard changes?")) open = false;
}
}
Opening and closing are idempotent#
ShowAsync() on an open drawer and CloseAsync() on a closed drawer are
no-ops. They do not restart the animation or raise OpenChanged again. During
an opposite transition, the latest request wins.