Skip to content

Commit 1cc3cae

Browse files
committed
fix(material/sidenav): allow focus to escape to sidenav container
When the new `ConfigurableFocusTrap` is passed to a sidenav, it prevents focus from moving from the sidenav to the container. These changes pass in a predicate that allows for focus to escape. Fixes #21955.
1 parent 62c9af3 commit 1cc3cae

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/material/sidenav/drawer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,10 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr
354354
}
355355

356356
ngAfterContentInit() {
357-
this._focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement);
357+
this._focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement, {
358+
defer: false,
359+
focusEscapePredicate: target => !!this._container?._element.nativeElement.contains(target)
360+
});
358361
this._updateFocusTrapState();
359362
}
360363

@@ -593,7 +596,7 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
593596
}
594597

595598
constructor(@Optional() private _dir: Directionality,
596-
private _element: ElementRef<HTMLElement>,
599+
public _element: ElementRef<HTMLElement>,
597600
private _ngZone: NgZone,
598601
private _changeDetectorRef: ChangeDetectorRef,
599602
viewportRuler: ViewportRuler,

tools/public_api_guard/material/sidenav.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export declare class MatDrawerContainer implements AfterContentInit, DoCheck, On
5959
right: number | null;
6060
};
6161
_drawers: QueryList<MatDrawer>;
62+
_element: ElementRef<HTMLElement>;
6263
_userContent: MatDrawerContent;
6364
get autosize(): boolean;
6465
set autosize(value: boolean);

0 commit comments

Comments
 (0)