@@ -54,7 +54,6 @@ import { ModalDialogComponent } from '../modal-dialog/modal-dialog.component';
54
54
imports : [ ModalDialogComponent , ModalContentComponent , A11yModule ]
55
55
} )
56
56
export class ModalComponent implements OnInit , OnDestroy , AfterViewInit {
57
-
58
57
#destroyRef = inject ( DestroyRef ) ;
59
58
#focusMonitor = inject ( FocusMonitor ) ;
60
59
@@ -64,7 +63,7 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
64
63
private hostElement : ElementRef ,
65
64
private modalService : ModalService ,
66
65
private backdropService : BackdropService
67
- ) { }
66
+ ) { }
68
67
69
68
/**
70
69
* Align the modal in the center or top of the screen.
@@ -110,14 +109,15 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
110
109
* @type boolean
111
110
* @default null
112
111
*/
113
- @Input ( ) @HostBinding ( 'attr.aria-modal' )
112
+ @Input ( )
113
+ @HostBinding ( 'attr.aria-modal' )
114
114
set ariaModal ( value : boolean | null ) {
115
115
this . #ariaModal = value ;
116
116
}
117
117
118
118
get ariaModal ( ) : boolean | null {
119
119
return this . visible || this . #ariaModal ? true : null ;
120
- } ;
120
+ }
121
121
122
122
#ariaModal: boolean | null = null ;
123
123
@@ -154,8 +154,12 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
154
154
this . #activeElement = this . document . activeElement as HTMLElement ;
155
155
// this.#activeElement?.blur();
156
156
setTimeout ( ( ) => {
157
- const focusable = this . modalContentRef . nativeElement . querySelectorAll ( '[tabindex]:not([tabindex="-1"]), button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled])' ) ;
158
- this . #focusMonitor. focusVia ( focusable [ 0 ] , 'keyboard' ) ;
157
+ const focusable = this . modalContentRef . nativeElement . querySelectorAll (
158
+ '[tabindex]:not([tabindex="-1"]), button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled])'
159
+ ) ;
160
+ if ( focusable . length ) {
161
+ this . #focusMonitor. focusVia ( focusable [ 0 ] , 'keyboard' ) ;
162
+ }
159
163
} ) ;
160
164
} else {
161
165
if ( this . document . contains ( this . #activeElement) ) {
@@ -191,7 +195,7 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
191
195
@HostBinding ( 'attr.aria-hidden' )
192
196
get ariaHidden ( ) : boolean | null {
193
197
return this . visible ? null : true ;
194
- } ;
198
+ }
195
199
196
200
@HostBinding ( 'attr.tabindex' )
197
201
get tabIndex ( ) : string | null {
@@ -255,15 +259,13 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
255
259
256
260
@HostListener ( 'click' , [ '$event' ] )
257
261
public onClickHandler ( $event : MouseEvent ) : void {
258
-
259
262
if ( this . mouseDownTarget !== $event . target ) {
260
263
this . mouseDownTarget = null ;
261
264
return ;
262
265
}
263
266
264
267
const targetElement = $event . target ;
265
268
if ( targetElement === this . hostElement . nativeElement ) {
266
-
267
269
if ( this . backdrop === 'static' ) {
268
270
this . setStaticBackdrop ( ) ;
269
271
return ;
@@ -289,27 +291,23 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
289
291
}
290
292
291
293
private stateToggleSubscribe ( ) : void {
292
- this . modalService . modalState$
293
- . pipe (
294
- takeUntilDestroyed ( this . #destroyRef)
295
- )
296
- . subscribe (
297
- ( action ) => {
298
- if ( this === action . modal || this . id === action . id ) {
299
- if ( 'show' in action ) {
300
- this . visible = action ?. show === 'toggle' ? ! this . visible : action . show ;
301
- }
302
- } else {
303
- if ( this . visible ) {
304
- this . visible = false ;
305
- }
306
- }
294
+ this . modalService . modalState$ . pipe ( takeUntilDestroyed ( this . #destroyRef) ) . subscribe ( ( action ) => {
295
+ if ( this === action . modal || this . id === action . id ) {
296
+ if ( 'show' in action ) {
297
+ this . visible = action ?. show === 'toggle' ? ! this . visible : action . show ;
298
+ }
299
+ } else {
300
+ if ( this . visible ) {
301
+ this . visible = false ;
307
302
}
308
- ) ;
303
+ }
304
+ } ) ;
309
305
}
310
306
311
307
private setBackdrop ( setBackdrop : boolean ) : void {
312
- this . #activeBackdrop = setBackdrop ? this . backdropService . setBackdrop ( 'modal' ) : this . backdropService . clearBackdrop ( this . #activeBackdrop) ;
308
+ this . #activeBackdrop = setBackdrop
309
+ ? this . backdropService . setBackdrop ( 'modal' )
310
+ : this . backdropService . clearBackdrop ( this . #activeBackdrop) ;
313
311
}
314
312
315
313
private setBodyStyles ( open : boolean ) : void {
0 commit comments