@@ -19,7 +19,7 @@ import {
1919 OnDestroy ,
2020 Renderer2
2121} from '@angular/core' ;
22- import { Subject } from 'rxjs' ;
22+ import { fromEvent , Subject } from 'rxjs' ;
2323import { takeUntil } from 'rxjs/operators' ;
2424
2525import { NzConfigService } from 'ng-zorro-antd/core/config' ;
@@ -70,7 +70,7 @@ export class BaseModalContainerComponent extends BasePortalOutlet implements OnD
7070
7171 constructor (
7272 protected ngZone : NgZone ,
73- protected elementRef : ElementRef ,
73+ protected host : ElementRef < HTMLElement > ,
7474 protected focusTrapFactory : FocusTrapFactory ,
7575 public cdr : ChangeDetectorRef ,
7676 protected render : Renderer2 ,
@@ -98,18 +98,6 @@ export class BaseModalContainerComponent extends BasePortalOutlet implements OnD
9898 }
9999 }
100100
101- onMousedown ( ) : void {
102- this . mouseDown = true ;
103- }
104-
105- onMouseup ( ) : void {
106- if ( this . mouseDown ) {
107- setTimeout ( ( ) => {
108- this . mouseDown = false ;
109- } ) ;
110- }
111- }
112-
113101 onCloseClick ( ) : void {
114102 this . cancelTriggered . emit ( ) ;
115103 }
@@ -142,7 +130,7 @@ export class BaseModalContainerComponent extends BasePortalOutlet implements OnD
142130 }
143131
144132 getNativeElement ( ) : HTMLElement {
145- return this . elementRef . nativeElement ;
133+ return this . host . nativeElement ;
146134 }
147135
148136 private animationDisabled ( ) : boolean {
@@ -163,19 +151,19 @@ export class BaseModalContainerComponent extends BasePortalOutlet implements OnD
163151
164152 private savePreviouslyFocusedElement ( ) : void {
165153 if ( ! this . focusTrap ) {
166- this . focusTrap = this . focusTrapFactory . create ( this . elementRef . nativeElement ) ;
154+ this . focusTrap = this . focusTrapFactory . create ( this . host . nativeElement ) ;
167155 }
168156
169157 if ( this . document ) {
170158 this . elementFocusedBeforeModalWasOpened = this . document . activeElement as HTMLElement ;
171- if ( this . elementRef . nativeElement . focus ) {
172- this . ngZone . runOutsideAngular ( ( ) => Promise . resolve ( ) . then ( ( ) => this . elementRef . nativeElement . focus ( ) ) ) ;
159+ if ( this . host . nativeElement . focus ) {
160+ this . ngZone . runOutsideAngular ( ( ) => Promise . resolve ( ) . then ( ( ) => this . host . nativeElement . focus ( ) ) ) ;
173161 }
174162 }
175163 }
176164
177165 private trapFocus ( ) : void {
178- const element = this . elementRef . nativeElement ;
166+ const element = this . host . nativeElement ;
179167
180168 if ( this . config . nzAutofocus ) {
181169 this . focusTrap . focusInitialElementWhenReady ( ) ;
@@ -193,7 +181,7 @@ export class BaseModalContainerComponent extends BasePortalOutlet implements OnD
193181 // We need the extra check, because IE can set the `activeElement` to null in some cases.
194182 if ( toFocus && typeof toFocus . focus === 'function' ) {
195183 const activeElement = this . document . activeElement as Element ;
196- const element = this . elementRef . nativeElement ;
184+ const element = this . host . nativeElement ;
197185
198186 if (
199187 ! activeElement ||
@@ -337,4 +325,24 @@ export class BaseModalContainerComponent extends BasePortalOutlet implements OnD
337325 this . destroy$ . next ( ) ;
338326 this . destroy$ . complete ( ) ;
339327 }
328+
329+ protected setupMouseListeners ( modalContainer : ElementRef < HTMLElement > ) : void {
330+ this . ngZone . runOutsideAngular ( ( ) => {
331+ fromEvent ( this . host . nativeElement , 'mouseup' )
332+ . pipe ( takeUntil ( this . destroy$ ) )
333+ . subscribe ( ( ) => {
334+ if ( this . mouseDown ) {
335+ setTimeout ( ( ) => {
336+ this . mouseDown = false ;
337+ } ) ;
338+ }
339+ } ) ;
340+
341+ fromEvent ( modalContainer . nativeElement , 'mousedown' )
342+ . pipe ( takeUntil ( this . destroy$ ) )
343+ . subscribe ( ( ) => {
344+ this . mouseDown = true ;
345+ } ) ;
346+ } ) ;
347+ }
340348}
0 commit comments