Confirm

lightning/confirm

Create a confirm modal within your component that asks the user to respond before they continue.

For Use In

Lightning Experience, Experience Builder Sites, Lightning Out (Beta), Standalone Lightning App

The lightning/confirm module lets you create a confirm modal within your component. Use LightningConfirm on your component to ask the user to respond before they continue.

Use LightningConfirm.open() instead of the native window.confirm() for a more consistent user experience. They have similar functions, but LightningConfirm.open() works in cross-origin iframes, where the .confirm() method is no longer supported in Chrome and Safari. Unlike window.confirm(), 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 has closed.

Import LightningConfirm from the lightning/confirm module in the component that will launch the confirm modal, and call LightningConfirm.open() with your desired attributes.

This example creates a headerless confirm modal with two buttons, OK and Cancel. The .open() function returns a promise that resolves to true when you click OK and false when you click Cancel.

This component uses the Salesforce Lightning Design System (SLDS) prompt blueprint.

LightningConfirm supports the following attributes:

  • message: Message text that displays in the confirm.
  • label: Header text, also used as the aria-label. Default string is Confirm.
  • variant: Two values, header and headerless. Default value is header.
  • theme: Color theme for the header. The theme attribute supports the following options from SLDS:
    • default: white
    • shade: gray
    • inverse: dark blue
    • alt-inverse: darker blue
    • success: green
    • info: gray-ish blue
    • warning: yellow
    • error: red
    • offline: ​black​

If an invalid value is provided, LightningConfirm uses the default theme. LightningConfirm ignores the style attribute.

Code using LightningConfirm can be tested by mocking the LightningConfirm.open() method.

The example below uses a button to open a confirm dialog and sets the result in a template.