@@ -21,7 +21,6 @@ import {
21
21
} from '@angular/core' ;
22
22
import { DOCUMENT } from '@angular/common' ;
23
23
import { BooleanInput , coerceBooleanProperty } from '@angular/cdk/coercion' ;
24
- import { FocusMonitor } from '@angular/cdk/a11y' ;
25
24
import { Subscription } from 'rxjs' ;
26
25
27
26
import { createPopper , Instance , Options , Placement } from '@popperjs/core' ;
@@ -118,6 +117,15 @@ export class DropdownComponent implements AfterContentInit, OnDestroy, OnInit {
118
117
static ngAcceptInputType_dark : BooleanInput ;
119
118
static ngAcceptInputType_visible : BooleanInput ;
120
119
120
+ constructor (
121
+ @Inject ( DOCUMENT ) private document : Document ,
122
+ private elementRef : ElementRef ,
123
+ private renderer : Renderer2 ,
124
+ private ngZone : NgZone ,
125
+ private changeDetectorRef : ChangeDetectorRef ,
126
+ public dropdownService : DropdownService
127
+ ) { }
128
+
121
129
/**
122
130
* Set alignment of dropdown menu.
123
131
* @type {'start' | 'end' | { xs: 'start' | 'end' } | { sm: 'start' | 'end' } | { md: 'start' | 'end' } | { lg: 'start' | 'end' } | { xl: 'start' | 'end'} | { xxl: 'start' | 'end'} }
@@ -246,23 +254,14 @@ export class DropdownComponent implements AfterContentInit, OnDestroy, OnInit {
246
254
dropdownContext = { $implicit : this . visible } ;
247
255
@ContentChild ( DropdownToggleDirective ) _toggler ! : DropdownToggleDirective ;
248
256
@ContentChild ( DropdownMenuDirective ) _menu ! : DropdownMenuDirective ;
257
+ @ContentChild ( DropdownMenuDirective , { read : ElementRef } ) _menuElementRef ! : ElementRef ;
249
258
250
259
public activeTrap = false ;
251
260
252
261
private dropdownStateSubscription ! : Subscription ;
253
262
private popperInstance ! : Instance | undefined ;
254
263
private listeners : ( ( ) => void ) [ ] = [ ] ;
255
264
256
- constructor (
257
- @Inject ( DOCUMENT ) private document : Document ,
258
- private elementRef : ElementRef ,
259
- private renderer : Renderer2 ,
260
- private ngZone : NgZone ,
261
- private changeDetectorRef : ChangeDetectorRef ,
262
- private focusMonitor : FocusMonitor ,
263
- public dropdownService : DropdownService
264
- ) { }
265
-
266
265
@HostBinding ( 'class' )
267
266
get hostClasses ( ) : any {
268
267
return {
@@ -320,14 +319,6 @@ export class DropdownComponent implements AfterContentInit, OnDestroy, OnInit {
320
319
if ( this . variant === 'nav-item' ) {
321
320
this . renderer . addClass ( this . _toggler . elementRef . nativeElement , 'nav-link' ) ;
322
321
}
323
- this . focusMonitor . monitor ( this . elementRef , true ) . subscribe ( origin => {
324
- this . ngZone . run ( ( ) => {
325
- if ( ( ! origin ) && ( this . autoClose === true || this . autoClose === 'outside' ) ) {
326
- this . setVisibleState ( false ) ;
327
- this . changeDetectorRef . markForCheck ( ) ;
328
- }
329
- } ) ;
330
- } ) ;
331
322
}
332
323
333
324
ngOnInit ( ) : void {
@@ -336,7 +327,6 @@ export class DropdownComponent implements AfterContentInit, OnDestroy, OnInit {
336
327
}
337
328
338
329
ngOnDestroy ( ) : void {
339
- this . focusMonitor ?. stopMonitoring ( this . elementRef ) ;
340
330
this . clearListeners ( ) ;
341
331
this . dropdownStateSubscribe ( false ) ;
342
332
this . destroyPopperInstance ( ) ;
@@ -380,6 +370,9 @@ export class DropdownComponent implements AfterContentInit, OnDestroy, OnInit {
380
370
this . listeners . push (
381
371
this . renderer . listen ( this . document , 'click' , ( event ) => {
382
372
const target = event . target as HTMLElement ;
373
+ if ( this . _menuElementRef ?. nativeElement . contains ( event . target ) ) {
374
+ this . clickedTarget = target ;
375
+ }
383
376
if ( this . _toggler ?. elementRef . nativeElement . contains ( event . target ) ) {
384
377
return ;
385
378
}
@@ -406,6 +399,14 @@ export class DropdownComponent implements AfterContentInit, OnDestroy, OnInit {
406
399
}
407
400
} )
408
401
) ;
402
+ this . listeners . push (
403
+ this . renderer . listen ( this . document , 'keyup' , ( event ) => {
404
+ if ( event . key === 'Tab' && this . autoClose !== false && ! this . elementRef . nativeElement . contains ( event . target ) ) {
405
+ this . setVisibleState ( false ) ;
406
+ return ;
407
+ }
408
+ } )
409
+ ) ;
409
410
}
410
411
411
412
private clearListeners ( ) : void {
0 commit comments