Skip to content

fix(AlertDialog): focus Cancel element on open per APG alertdialog pattern#630

Open
sridhar-3009 wants to merge 4 commits into
vuetifyjs:masterfrom
sridhar-3009:fix/alert-dialog-cancel-focus-609
Open

fix(AlertDialog): focus Cancel element on open per APG alertdialog pattern#630
sridhar-3009 wants to merge 4 commits into
vuetifyjs:masterfrom
sridhar-3009:fix/alert-dialog-cancel-focus-609

Conversation

@sridhar-3009

Copy link
Copy Markdown
Contributor

Problem

The AlertDialog docs state that initial focus should land on the Cancel button — the least-destructive action — per the WAI-ARIA Authoring Practices alertdialog pattern. However, AlertDialogContent never called .focus() on the Cancel element; focus landed wherever the browser defaulted.

Closes #609.

Solution

  1. AlertDialogRoot.vue — Added cancelEl: ShallowRef<HTMLElement | null> to AlertDialogContext so child components can share a reference to the Cancel button's DOM element.

  2. AlertDialogCancel.vue — Added ref="cancel" on the Atom element, then used onMounted/onUnmounted to register/deregister the underlying DOM element in context.cancelEl.

  3. AlertDialogContent.vue — Added focusCancel() (context.cancelEl.value?.focus()) and called it immediately after showModal() in both the watch handler and onMounted.

…ttern (closes vuetifyjs#609)

Register the Cancel element via onMounted/onUnmounted in AlertDialogCancel, store it
on context, and call cancelEl.focus() whenever the dialog opens — matching the APG
recommendation that alertdialog initial focus lands on the least-destructive action.
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Changeset found — this change will be included in the next release. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] AlertDialog: documented initial focus on Cancel is never wired

1 participant