React playground

Nova v3.38.0

Preview

React

nv-drawer migration

How opening and closing the drawer changed after 3.38, and how to adapt your code.

← nv-drawer

Migration Guide for nv-drawer

The open/close behaviour of nv-drawer has been aligned with nv-dialog. This page lists the behaviour changes introduced after version 3.38 and how to adapt code that relied on the previous behaviour. The component API itself (properties, events, methods, slots) is unchanged.

Behaviour Changes#

1. openChanged is no longer emitted when you change open yourself#

Previously, every change of open emitted openChanged, including changes made by your own code (setting the property or attribute, or a framework binding). Now openChanged is only emitted when the drawer opens or closes itself: trigger, close button, Escape key, backdrop click, swipe, footer Cancel, or a call to show() / close().

This is the same contract nv-dialog has. Echoing a consumer's own write back to it made every write a feedback source; over an asynchronous transport (Blazor Server) two opposite writes in flight could make the drawer open and close indefinitely.

Two-way bindings (for example @bind-Open in Blazor) are not affected: the consumer already holds the value it wrote.

Old Usage: relying on the echo to run code after opening programmatically

javascriptdrawer.addEventListener('openChanged', event => {
  if (event.detail) loadDrawerData();
});

drawer.open = true; // used to emit openChanged(true)

New Usage: run that code where you open the drawer, and keep the listener for the drawer's own transitions

javascriptdrawer.addEventListener('openChanged', event => {
  if (event.detail) loadDrawerData(); // trigger, show(), swipe
});

drawer.open = true;
loadDrawerData(); // your own write is not echoed

Previously only the drawer's built-in footer closed the drawer on Cancel. A footer you provided yourself (<nv-drawerfooter slot="footer">) emitted drawerCanceled, but the drawer stayed open unless your code closed it. Now a slotted nv-drawerfooter behaves like the built-in one, as documented: Cancel closes the drawer. drawerCanceled is still emitted, so existing listeners keep working; closing the drawer from such a listener is now redundant but harmless.

If you need to keep the drawer open on Cancel (for example to ask for confirmation first), use controlled mode. In controlled mode the drawer does not wire the trigger or a slotted footer's Cancel, so you decide when it closes. The close button, Escape and a backdrop click (click-outside) still close it; set undismissable as well if those must go through your confirmation too.

html<nv-drawer id="editDrawer" controlled>
  <nv-drawerheader heading="Edit item"></nv-drawerheader>
  <p>…</p>
  <nv-drawerfooter slot="footer" cancel-label="Cancel"></nv-drawerfooter>
</nv-drawer>

<script>
  const drawer = document.getElementById('editDrawer');
  const footer = drawer.querySelector('nv-drawerfooter');

  footer.addEventListener('drawerCanceled', async () => {
    if (await confirmDiscardChanges()) {
      drawer.open = false;
    }
  });
</script>

3. Opening and closing are idempotent#

Calling show() on a drawer that is already open (or close() on one that is already closed) is now a no-op: it no longer restarts the animation or emits openChanged again. Opening a drawer while it is still closing, or closing it while it is still opening, still works: the latest request wins.