Skip to content

Commit 716ec21

Browse files
committed
fix(drawer): not restoring focus on close
Currently the drawer restores focus on close after its closing animation is done and it contains the currently-focused element. This will always evaluate to false, because the sidenav gets a `visibility: hidden` which will blur any focused elements that it may have. With these changes the drawer will restore focus when the animation starts and it's still visible.
1 parent 4d97271 commit 716ec21

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/lib/sidenav/drawer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
212212
this._focusTrap.focusInitialElementWhenReady();
213213
}
214214
});
215-
216-
this.onClose.subscribe(() => this._restoreFocus());
217215
}
218216

219217
/**
@@ -277,6 +275,7 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
277275
this._animationState = this._enableAnimations ? 'open' : 'open-instant';
278276
} else {
279277
this._animationState = 'void';
278+
this._restoreFocus();
280279
}
281280

282281
if (this._focusTrap) {

0 commit comments

Comments
 (0)