New feature for Modal: listener to close event

A modal can be created and opened:

const modal =;

and with the ‘modal’ reference, it is possible to close the modal

but if there is a backdrop, the modal can be closed by the user/visitor clicking on it (or outside the modal), then the modal is closed but it’s not possible to get this ‘event’. I didn’t find any solution for this reading the API doc.

My proposal is to add some kind of event listener, like:

modal.on('close', someCallbackFunction)

or as a promise
modal.closed().then( someHandler )

1 possible answer(s) on “New feature for Modal: listener to close event

  1. You can do this today:

    const modal =;
    modal. result.then(() => { console.log('When user closes'); }, () => { console.log('Backdrop click')})

    In other words, the result promise is rejected when a user clicks on backdrop, uses the ESC key.