@@ -358,21 +358,23 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
358
358
359
359
/** Stream of clicks outside of the autocomplete panel. */
360
360
private _getOutsideClickStream ( ) : Observable < any > {
361
+ // Use capturing so we can close even if propagation is stopped.
362
+ const eventOptions = { capture : true } ;
361
363
return merge (
362
- fromEvent ( this . _document , 'click' ) as Observable < MouseEvent > ,
363
- fromEvent ( this . _document , 'touchend' ) as Observable < TouchEvent > )
364
- . pipe ( filter ( event => {
365
- // If we're in the Shadow DOM, the event target will be the shadow root, so we have to
366
- // fall back to check the first element in the path of the click event.
367
- const clickTarget =
368
- ( this . _isInsideShadowRoot && event . composedPath ? event . composedPath ( ) [ 0 ] :
369
- event . target ) as HTMLElement ;
370
- const formField = this . _formField ? this . _formField . _elementRef . nativeElement : null ;
371
-
372
- return this . _overlayAttached && clickTarget !== this . _element . nativeElement &&
373
- ( ! formField || ! formField . contains ( clickTarget ) ) &&
374
- ( ! ! this . _overlayRef && ! this . _overlayRef . overlayElement . contains ( clickTarget ) ) ;
375
- } ) ) ;
364
+ fromEvent ( this . _document , 'click' , eventOptions ) as Observable < MouseEvent > ,
365
+ fromEvent ( this . _document , 'touchend' , eventOptions ) as Observable < TouchEvent >
366
+ ) . pipe ( filter ( event => {
367
+ // If we're in the Shadow DOM, the event target will be the shadow root, so we have to
368
+ // fall back to check the first element in the path of the click event.
369
+ const clickTarget =
370
+ ( this . _isInsideShadowRoot && event . composedPath ? event . composedPath ( ) [ 0 ] :
371
+ event . target ) as HTMLElement ;
372
+ const formField = this . _formField ? this . _formField . _elementRef . nativeElement : null ;
373
+
374
+ return this . _overlayAttached && clickTarget !== this . _element . nativeElement &&
375
+ ( ! formField || ! formField . contains ( clickTarget ) ) &&
376
+ ( ! ! this . _overlayRef && ! this . _overlayRef . overlayElement . contains ( clickTarget ) ) ;
377
+ } ) ) ;
376
378
}
377
379
378
380
// Implemented as part of ControlValueAccessor.
0 commit comments