Confirm Dialog
- Usage
- Styling
Confirm Dialog is a modal Dialog used to confirm user actions.
new tab
status = new Span();
status.setVisible(false);
ConfirmDialog dialog = new ConfirmDialog();
dialog.setHeader("Unsaved changes");
dialog.setText(
"There are unsaved changes. Do you want to discard or save them?");
dialog.setCancelable(true);
dialog.addCancelListener(event -> setStatus("Canceled"));
dialog.setRejectable(true);
dialog.setRejectText("Discard");
dialog.addRejectListener(event -> setStatus("Discarded"));
dialog.setConfirmText("Save");
dialog.addConfirmListener(event -> setStatus("Saved"));
Button button = new Button("Open confirm dialog");
button.addClickListener(event -> {
dialog.open();
status.setVisible(false);
});
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.
new tab
status = new Span();
status.setVisible(false);
ConfirmDialog dialog = new ConfirmDialog();
dialog.setHeader("Export failed");
dialog.setText(new Html(
"<p>An error occurred while exporting <b>Report Q4</b>. Please try again. If the problem persists, contact <a href=\"mailto:[email protected]\">[email protected]</a>.</p>"));
dialog.setConfirmText("OK");
dialog.addConfirmListener(event -> setStatus("Acknowledged"));
Button button = new Button("Open confirm dialog");
button.addClickListener(event -> {
dialog.open();
status.setVisible(false);
});
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.
new tab
status = new Span();
status.setVisible(false);
ConfirmDialog dialog = new ConfirmDialog();
dialog.setHeader("Delete \"Report Q4\"?");
dialog.setText(
"Are you sure you want to permanently delete this item?");
dialog.setCancelable(true);
dialog.addCancelListener(event -> setStatus("Canceled"));
dialog.setConfirmText("Delete");
dialog.setConfirmButtonTheme("error primary");
dialog.addConfirmListener(event -> setStatus("Deleted"));
Button button = new Button("Open confirm dialog");
button.addClickListener(event -> {
dialog.open();
status.setVisible(false);
});
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.
new tab
status = new Span();
status.setVisible(false);
ConfirmDialog dialog = new ConfirmDialog();
dialog.setHeader("Unsaved changes");
dialog.setText(
"Do you want to discard or save your changes before navigating away?");
dialog.setCancelable(true);
dialog.addCancelListener(event -> setStatus("Canceled"));
dialog.setRejectable(true);
dialog.setRejectText("Discard");
dialog.addRejectListener(event -> setStatus("Discarded"));
dialog.setConfirmText("Save");
dialog.addConfirmListener(event -> setStatus("Saved"));
Button button = new Button("Open confirm dialog");
button.addClickListener(event -> {
dialog.open();
status.setVisible(false);
});
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.