Confirm Modals
Use a confirm modal to ask users to respond before they continue. To display a confirm modal in Lightning Experience, import LightningConfirm
from the lightning/confirm
module, and call LightningConfirm.open()
with your desired attributes.
This confirm modal 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 modal is closed.
This example component creates a button that opens the confirm modal UI 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.
For information about the attributes for the confirm modal, see the Component Reference.
See Also