Skip to content

Missing an event before closing an overlay #1092

Done

Description

@gygasync

A onBeforeClose or onBeforeUnload = (event, instance) would be useful especially when notifying the user that the changes that have not been saved will not be applied

Activity

  1. mstijak commented on Nov 24, 2026

    @mstijak
    Member

    Overlays (Window, Dropdown, ...) call overlayWillDismiss(instance, component) before they close, e.g. with Escape or the close button. Return false to keep the overlay open, e.g. after asking whether unsaved changes should be discarded.

  2. mstijak commented on Nov 24, 2026

    @mstijak
    Member

    Follow-up: since #1371 and #1372, overlays also support onBeforeDismiss, which is the more natural option for this. It is called before the overlay is dismissed, e.g. with Escape, the close button, a focus out with dismissOnFocusOut, the back button with dismissOnPopState, or the function returned by open(). Return false, or a promise that resolves to false, to keep the overlay open:

    <Window
       visible={m.editor.visible}
       title="Edit"
       onBeforeDismiss={async (instance) =>
          !instance.store.get(m.editor.dirty) || (await MsgBox.yesNo("Discard unsaved changes?")) == "yes"
       }
    >
       ...
    </Window>

    While the promise is pending, other attempts to dismiss the overlay are ignored, so the question is asked only once. onBeforeDismiss can also name a controller method, e.g. onBeforeDismiss="onBeforeDismiss". Setting visible to false in the store closes the overlay without calling it, so a Save button can close the window directly.

    Available from the next release; in earlier versions, use overlayWillDismiss as described above (synchronous only).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions