Trên trang này

Trang này chưa có bản tiếng Việt, nội dung bên dưới là bản tiếng Anh. Xem trang tiếng Anh

Dialog cảnh báo

Keys, what Alert dialog gives you and what your team does.

Conformance

Alert dialog meets WCAG 2.2 level AA when used as described on these pages. It follows the Alert and Message Dialogs pattern of the WAI-ARIA Authoring Practices.

Keyboard

Key Action
Tab Moves between Cancel and the action, wrapping inside the dialog.
Enter Space Presses the focused button.
Esc Cancels and closes. Focus returns to the trigger.

What Alert dialog gives you

  • role="alertdialog" and aria-modal="true", named by AlertDialogTitle and described by AlertDialogDescription, so screen readers read the question when it opens.
  • Cancel takes focus when the dialog opens.
  • Focus stays inside while it is open and returns to the trigger when it closes.
  • A click outside does not close it, so the answer is always a choice.
  • The page behind is hidden from screen readers and can’t be scrolled.

What your team does

  • Always include a title and a description.
  • Name the action with what it does, never “Yes” or “OK”.
  • Keep Cancel first and the action last (D10).
  • Give the media icon aria-hidden="true"; the text says it all.

WCAG criteria

Criterion Level How
1.3.1 Info and Relationships A Title and description linked to the dialog
2.1.1 Keyboard A Both buttons reachable; Esc cancels
2.4.3 Focus Order A Focus starts on Cancel and returns to the trigger
3.3.4 Error Prevention (Legal, Financial, Data) AA A confirming step before a can’t-undo action
4.1.2 Name, Role, Value A role="alertdialog", aria-modal, aria-labelledby, aria-describedby