Skip to content

Commit

Permalink
fix(material/dialog): Make focus behavior consistent across zoneful/z…
Browse files Browse the repository at this point in the history
…oneless apps (#29192)

(cherry picked from commit 3b32d0e)
  • Loading branch information
mmalerba committed Jun 10, 2024
1 parent 8dbd669 commit 6dd1689
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/cdk/dialog/dialog-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,17 @@ export class CdkDialogContainer<C extends DialogConfig = DialogConfig>
break;
case true:
case 'first-tabbable':
this._focusTrap?.focusInitialElementWhenReady().then(focusedSuccessfully => {
// If we weren't able to find a focusable element in the dialog, then focus the dialog
// container instead.
if (!focusedSuccessfully) {
this._focusDialogContainer();
}
});
afterNextRender(
() => {
const focusedSuccessfully = this._focusTrap?.focusInitialElement();
// If we weren't able to find a focusable element in the dialog, then focus the dialog
// container instead.
if (!focusedSuccessfully) {
this._focusDialogContainer();
}
},
{injector: this._injector},
);
break;
case 'first-heading':
afterNextRender(
Expand Down

0 comments on commit 6dd1689

Please sign in to comment.