Skip to content

Commit 3b32d0e

Browse files
authored
fix(material/dialog): Make focus behavior consistent across zoneful/zoneless apps (#29192)
1 parent 6fd57c2 commit 3b32d0e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/cdk/dialog/dialog-container.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,17 @@ export class CdkDialogContainer<C extends DialogConfig = DialogConfig>
283283
break;
284284
case true:
285285
case 'first-tabbable':
286-
this._focusTrap?.focusInitialElementWhenReady().then(focusedSuccessfully => {
287-
// If we weren't able to find a focusable element in the dialog, then focus the dialog
288-
// container instead.
289-
if (!focusedSuccessfully) {
290-
this._focusDialogContainer();
291-
}
292-
});
286+
afterNextRender(
287+
() => {
288+
const focusedSuccessfully = this._focusTrap?.focusInitialElement();
289+
// If we weren't able to find a focusable element in the dialog, then focus the dialog
290+
// container instead.
291+
if (!focusedSuccessfully) {
292+
this._focusDialogContainer();
293+
}
294+
},
295+
{injector: this._injector},
296+
);
293297
break;
294298
case 'first-heading':
295299
afterNextRender(

0 commit comments

Comments
 (0)