Documentation

Documentation versions (currently viewingVaadin 24)

Confirm Dialog

Confirm Dialog is a modal Dialog used to confirm user actions.

Confirm Dialog is a modal Dialog used to confirm user actions.

Open in a
new tab
<vaadin-confirm-dialog
  header="Unsaved changes"
  cancel-button-visible
  reject-button-visible
  reject-text="Discard"
  confirm-text="Save"
  .opened="${this.dialogOpened}"
  @opened-changed="${this.openedChanged}"
  @confirm="${() => {
    this.status = 'Saved';
  }}"
  @cancel="${() => {
    this.status = 'Canceled';
  }}"
  @reject="${() => {
    this.status = 'Discarded';
  }}"
>
  There are unsaved changes. Do you want to discard or save them?
</vaadin-confirm-dialog>

Content

Confirm Dialog consists of:

  • Title

  • Message

  • Footer

    • “Cancel” button

    • “Reject” button

    • “Confirm” button

Each Confirm Dialog should have a title and/or message. The “Confirm” button is shown by default, while the two other buttons aren’t (they must be explicitly enabled to be displayed).

Title

The title should be brief but informative and written in sentence case. It must explain the purpose of the dialog and can be phrased as a statement or question. Avoid ambiguous titles, such as “Are you sure?”. Rich content, such as other components and elements, can also be used in the title.

Messages

The message should contain any information a user might need to make an informed decision.

While it can contain any type of content, Confirm Dialog isn’t meant for collecting user input, except for a Checkbox used for remembering the user’s choice.

Buttons

The buttons in a Confirm Dialog are customizable. You can edit their labels and change their theme variants.

Confirm Button

The “Confirm” button represents primary action and is the only button that’s visible by default. Every dialog needs at least one button.

As the name suggests, its default label is “Confirm”, but it can and should be relabeled based on the use case.

Usage Recommendations

  • Use concise labels that explain the action, such as “Save” and “Delete”. Avoid ambiguous labels like “Yes” and “No”.

  • For dangerous actions, such as those that lose or destroy data, use the Error theme variant.

  • For simple acknowledgements, it’s acceptable to use an “OK” label.

Open in a
new tab
<vaadin-confirm-dialog
  header="Export failed"
  confirm-text="OK"
  .opened="${this.dialogOpened}"
  @opened-changed="${this.openedChanged}"
  @confirm="${() => {
    this.status = 'Acknowledged';
  }}"
>
  An error occurred while exporting <b>Report Q4</b>. Please try again. If the problem
  persists, contact <a href="mailto:support@company.com">support@company.com</a>.
</vaadin-confirm-dialog>

Cancel Button

The “Cancel” button is used in situations where the user must be able to cancel an action altogether, such as confirming irreversible actions like saving or deleting data.

Open in a
new tab
<vaadin-confirm-dialog
  header='Delete "Report Q4"?'
  cancel-button-visible
  confirm-text="Delete"
  confirm-theme="error primary"
  .opened="${this.dialogOpened}"
  @opened-changed="${this.openedChanged}"
  @cancel="${() => {
    this.status = 'Canceled';
  }}"
  @confirm="${() => {
    this.status = 'Deleted';
  }}"
>
  Are you sure you want to permanently delete this item?
</vaadin-confirm-dialog>

Reject Button

The “Reject” button differs from the “Cancel” button in that it still moves the user forward in their workflow.

For example, if the user tries to leave a view containing unsaved changes, they are typically presented with three options: “Cancel”, “Discard” and “Save”. “Cancel” allows the user to stay put and review their changes. “Discard” (the “Reject” button in this case) gets rid of the changes and the user leaves the view.

Open in a
new tab
<vaadin-confirm-dialog
  header="Unsaved changes"
  cancel-button-visible
  reject-button-visible
  reject-text="Discard"
  confirm-text="Save"
  .opened="${this.dialogOpened}"
  @opened-changed="${this.openedChanged}"
  @confirm="${() => {
    this.status = 'Saved';
  }}"
  @cancel="${() => {
    this.status = 'Canceled';
  }}"
  @reject="${() => {
    this.status = 'Discarded';
  }}"
>
  Do you want to discard or save your changes before navigating away?
</vaadin-confirm-dialog>

Closing

Confirm Dialog can be closed by clicking one of its buttons (all buttons close the dialog by default), or by pressing Esc (which triggers the action associated with the Cancel button if one exists). Closing on Esc can be disabled by setting the noCloseOnEsc property to false.

Component Usage Recommendations

Dialog

Component for presenting information and UI elements in an overlay.

8D87F369-290E-455A-A57A-D007698097E7