Skip to content

Commit 77addc6

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 77addc6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/lib/sidenav/drawer.ts

Lines changed: 6 additions & 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
/**
@@ -302,7 +300,13 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
302300
}
303301

304302
_onAnimationStart(event: AnimationEvent) {
303+
const {fromState, toState} = event;
304+
305305
this._animationStarted.emit(event);
306+
307+
if (fromState !== toState && toState === 'void') {
308+
this._restoreFocus();
309+
}
306310
}
307311

308312
_onAnimationEnd(event: AnimationEvent) {

0 commit comments

Comments
 (0)