Skip to content

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

Open
sridhar-3009 wants to merge 5 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 5 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!

Two branch/statement gaps left by codecov's patch-coverage check:

- AlertDialogCancel.vue:63 — the cancelRef.value?.element ?? null
  fallback only fires when Atom exposes no element (renderless mode).
  No existing test rendered Cancel as renderless.
- AlertDialogContent.vue:159-160 — onClose() was wired to the native
  'close' event but nothing dispatched one; only the parallel onCancel
  path (native 'cancel' event) had coverage.

Add one test for each.
@johnleider johnleider added T: bug Something isn't working C: Dialog Dialog component labels Jul 27, 2026
@johnleider johnleider added this to the v1.0.x milestone Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: Dialog Dialog component T: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants