Skip to content

fix(a11y): keep Material's dialog defaults - #373

Merged
Hakanbaban53 merged 1 commit into
Zarestia-Dev:masterfrom
repires:fix/dialog-default-options
Nov 25, 2026
Merged

Hakanbaban53 merged 1 commit into
Zarestia-Dev:masterfrom
repires:fix/dialog-default-options

Conversation

@repires

@repires repires commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Part of #354.

What

app.config.ts provides MAT_DIALOG_DEFAULT_OPTIONS as { closeOnNavigation: false }. Material uses that object in place of new MatDialogConfig(), not on top of it ({ ...(this._defaultOptions || new MatDialogConfig()), ...config }), so every dialog lost role="dialog", autoFocus: 'first-tabbable' and restoreFocus: true.

In the headless UI on master, opening Quick Remote or Preferences (by mouse or keyboard):

  • the dialog had no role, so screen readers don't announce it;
  • focus stayed on the menu button behind it, and Tab moved through the page underneath;
  • closing it didn't return focus to where it was.

The defaults now start from new MatDialogConfig() and keep closeOnNavigation: false. Nothing else changes visibly: the backdrop already came from the CDK's own defaults, Material sets no default size, and every app dialog sets its own size and disableClose. The first button inside a dialog now gets focus, so its focus highlight shows when it was opened by keyboard.

Tests

  • New app.config.spec.ts: the defaults keep role, autoFocus and restoreFocus, and a dialog opened with them has role="dialog", takes focus, and gives it back to the trigger when it closes. With the old value, both tests fail.
  • Checked in the headless UI with Playwright: Quick Remote, Detailed Remote, Preferences, Keyboard Shortcuts and About, each opened from its menu by keyboard, now have role="dialog", take focus, keep Tab inside for 25 presses, and return focus to the menu button on close.
  • Full suite (259 files, 3666 tests), ESLint, Prettier and ng build pass.

Follow-up: the dialogs still have no accessible name (no aria-labelledby on their title); that needs a per-dialog change, so it's not in this PR.

MAT_DIALOG_DEFAULT_OPTIONS replaces new MatDialogConfig() instead of
adding to it, so providing { closeOnNavigation: false } dropped
role="dialog", autoFocus and restoreFocus from every dialog. Dialogs
opened without a role, focus stayed on the button behind them, Tab moved
through the page underneath, and closing did not return focus. Start the
defaults from new MatDialogConfig() (Zarestia-Dev#354).
@Hakanbaban53
Hakanbaban53 merged commit f3a8b1c into Zarestia-Dev:master Nov 25, 2026
6 checks passed
@repires
repires deleted the fix/dialog-default-options branch November 25, 2026 07:56
Hakanbaban53 pushed a commit that referenced this pull request Nov 25, 2026
Dialogs had role="dialog" (#373) but no accessible name, so screen
readers announced only "dialog" (#354). Modals put their title in
<header><p>, not mat-dialog-title (which would also restyle it), so
DialogLabelsService links that title to the dialog the way the
directive does, through the container's aria-labelledby queue. A dialog
without a header (the confirm dialog) is named by its first h1 or h2.
Preferences shows its tabs instead of a title on wide windows, so it
opens with its title as aria-label.
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.

2 participants