@@ -235,6 +235,13 @@ export class DropdownComponent implements AfterContentInit, OnDestroy, OnInit {
235
235
return this . variant === 'input-group' ? { display : 'contents' } : { } ;
236
236
}
237
237
238
+ private clickedTarget ! : HTMLElement ;
239
+
240
+ @HostListener ( 'click' , [ '$event' ] )
241
+ private onHostClick ( $event : MouseEvent ) : void {
242
+ this . clickedTarget = $event . target as HTMLElement ;
243
+ }
244
+
238
245
dropdownStateSubscribe ( subscribe : boolean = true ) : void {
239
246
if ( subscribe ) {
240
247
this . dropdownStateSubscription =
@@ -313,28 +320,24 @@ export class DropdownComponent implements AfterContentInit, OnDestroy, OnInit {
313
320
}
314
321
315
322
private setListeners ( ) : void {
316
- const host = this . elementRef . nativeElement ;
317
323
this . listeners . push (
318
324
this . renderer . listen ( this . document , 'click' , ( event ) => {
325
+ const target = event . target as HTMLElement ;
319
326
if ( this . _toggler ?. elementRef . nativeElement . contains ( event . target ) ) {
320
327
return ;
321
328
}
322
329
if ( this . autoClose === true ) {
323
330
this . setVisibleState ( false ) ;
324
331
return ;
325
332
}
326
- if ( ! host . contains ( event . target ) ) {
327
- if ( this . autoClose === 'outside' ) {
333
+ if ( this . clickedTarget === target && this . autoClose === 'inside' ) {
328
334
this . setVisibleState ( false ) ;
329
335
return ;
330
336
}
331
- }
332
- if ( this . _menu . elementRef . nativeElement . contains ( event . target ) ) {
333
- if ( this . autoClose === 'inside' ) {
337
+ if ( this . clickedTarget !== target && this . autoClose === 'outside' ) {
334
338
this . setVisibleState ( false ) ;
335
339
return ;
336
340
}
337
- }
338
341
} )
339
342
) ;
340
343
this . listeners . push (
0 commit comments