From e68cd703adc452a1f0628971bd1d3c175f924ac2 Mon Sep 17 00:00:00 2001 From: AshBurns Date: Fri, 23 Jan 2026 11:15:23 +0000 Subject: [PATCH] feat(material/dialog): support string and HTMLElement for restoreFocus Aligns MatDialogConfig.restoreFocus with the CDK DialogConfig to allow specifying a CSS selector or HTMLElement to restore focus to when the dialog closes. --- goldens/material/dialog/index.api.md | 2 +- src/material/dialog/dialog-config.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/goldens/material/dialog/index.api.md b/goldens/material/dialog/index.api.md index 49517f7de6db..15e16db5e2b3 100644 --- a/goldens/material/dialog/index.api.md +++ b/goldens/material/dialog/index.api.md @@ -143,7 +143,7 @@ export class MatDialogConfig { minWidth?: number | string; panelClass?: string | string[]; position?: DialogPosition; - restoreFocus?: boolean; + restoreFocus?: boolean | string | HTMLElement; role?: DialogRole; scrollStrategy?: ScrollStrategy; viewContainerRef?: ViewContainerRef; diff --git a/src/material/dialog/dialog-config.ts b/src/material/dialog/dialog-config.ts index 0cfb0ae86234..3ff46899ef56 100644 --- a/src/material/dialog/dialog-config.ts +++ b/src/material/dialog/dialog-config.ts @@ -130,10 +130,14 @@ export class MatDialogConfig { autoFocus?: AutoFocusTarget | string | boolean = 'first-tabbable'; /** - * Whether the dialog should restore focus to the - * previously-focused element, after it's closed. + * Whether the dialog should restore focus to the previously-focused element upon closing. + * Has the following behavior based on the type that is passed in: + * - `boolean` - when true, will return focus to the element that was focused before the dialog + * was opened, otherwise won't restore focus at all. + * - `string` - focus will be restored to the first element that matches the CSS selector. + * - `HTMLElement` - focus will be restored to the specific element. */ - restoreFocus?: boolean = true; + restoreFocus?: boolean | string | HTMLElement = true; /** Whether to wait for the opening animation to finish before trapping focus. */ delayFocusTrap?: boolean = true;