Confirm Modals

Use a confirm modal to ask users to respond before they continue. The confirm modal is displayed as a dialog on top of the page content using an overlay.

To display a confirm modal in Lightning Experience, import LightningConfirm from the lightning/confirm module, and call LightningConfirm.open() with your desired attributes.

LightningConfirm is an alternative to the native window.confirm() function, which isn’t supported for cross-origin iframes in Chrome and Safari. Unlike the native confirm function, LightningConfirm.open() doesn't halt execution on the page, it returns a promise. Use async/await or .then() for any code you want to execute after the confirm modal is closed.

A headerless confirm modal over a darkened org.

This example component creates a button that opens the confirm modal that you see in the screenshot.

Import LightningConfirm from lightning/confirm in the JavaScript file of the component that opens the confirm modal. Create and dispatch a LightningConfirm event with message, variant, and label attributes. The .open() function returns a promise that resolves to true when you click OK and false when you click Cancel.

The lwc-recipes repo has a miscNotificationModules component that demonstrates confirm modals.

For information about the attributes for LightningConfirm, see the Component Reference.

See Also