diff --git a/components/drawer/nz-drawer.component.ts b/components/drawer/nz-drawer.component.ts index 865478f852..c383e47d44 100644 --- a/components/drawer/nz-drawer.component.ts +++ b/components/drawer/nz-drawer.component.ts @@ -296,10 +296,10 @@ export class NzDrawerComponent extends NzDrawerRef } private trapFocus(): void { - if (!this.focusTrap) { + if (!this.focusTrap && this.overlayRef && this.overlayRef.overlayElement) { this.focusTrap = this.focusTrapFactory.create(this.overlayRef!.overlayElement); + this.focusTrap.focusInitialElement(); } - this.focusTrap.focusInitialElement(); } private restoreFocus(): void {