@@ -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.
@@ -89,7 +88,7 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
89
88
* @type boolean
90
89
* @default true
91
90
*/
92
- @Input ( { transform : booleanAttribute } ) keyboard = true ;
91
+ @Input ( { transform : booleanAttribute } ) keyboard : boolean = true ;
93
92
@Input ( ) id ?: string ;
94
93
/**
95
94
* Size the component small, large, or extra large.
@@ -104,21 +103,21 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
104
103
* @type string
105
104
* @default 'dialog'
106
105
*/
107
- @Input ( ) @HostBinding ( 'attr.role' ) role = 'dialog' ;
108
-
106
+ @Input ( ) @HostBinding ( 'attr.role' ) role : string = 'dialog' ;
109
107
/**
110
108
* Set aria-modal html attr for modal. [docs]
111
109
* @type boolean
112
110
* @default null
113
111
*/
114
- @Input ( ) @HostBinding ( 'attr.aria-modal' )
112
+ @Input ( )
113
+ @HostBinding ( 'attr.aria-modal' )
115
114
set ariaModal ( value : boolean | null ) {
116
115
this . #ariaModal = value ;
117
116
}
118
117
119
118
get ariaModal ( ) : boolean | null {
120
119
return this . visible || this . #ariaModal ? true : null ;
121
- } ;
120
+ }
122
121
123
122
#ariaModal: boolean | null = null ;
124
123
@@ -155,8 +154,12 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
155
154
this . #activeElement = this . document . activeElement as HTMLElement ;
156
155
// this.#activeElement?.blur();
157
156
setTimeout ( ( ) => {
158
- const focusable = this . modalContentRef . nativeElement . querySelectorAll ( '[tabindex]:not([tabindex="-1"]), button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled])' ) ;
159
- 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
+ }
160
163
} ) ;
161
164
} else {
162
165
if ( this . document . contains ( this . #activeElement) ) {
@@ -192,7 +195,7 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
192
195
@HostBinding ( 'attr.aria-hidden' )
193
196
get ariaHidden ( ) : boolean | null {
194
197
return this . visible ? null : true ;
195
- } ;
198
+ }
196
199
197
200
@HostBinding ( 'attr.tabindex' )
198
201
get tabIndex ( ) : string | null {
@@ -256,15 +259,13 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
256
259
257
260
@HostListener ( 'click' , [ '$event' ] )
258
261
public onClickHandler ( $event : MouseEvent ) : void {
259
-
260
262
if ( this . mouseDownTarget !== $event . target ) {
261
263
this . mouseDownTarget = null ;
262
264
return ;
263
265
}
264
266
265
267
const targetElement = $event . target ;
266
268
if ( targetElement === this . hostElement . nativeElement ) {
267
-
268
269
if ( this . backdrop === 'static' ) {
269
270
this . setStaticBackdrop ( ) ;
270
271
return ;
@@ -290,27 +291,23 @@ export class ModalComponent implements OnInit, OnDestroy, AfterViewInit {
290
291
}
291
292
292
293
private stateToggleSubscribe ( ) : void {
293
- this . modalService . modalState$
294
- . pipe (
295
- takeUntilDestroyed ( this . #destroyRef)
296
- )
297
- . subscribe (
298
- ( action ) => {
299
- if ( this === action . modal || this . id === action . id ) {
300
- if ( 'show' in action ) {
301
- this . visible = action ?. show === 'toggle' ? ! this . visible : action . show ;
302
- }
303
- } else {
304
- if ( this . visible ) {
305
- this . visible = false ;
306
- }
307
- }
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 ;
308
302
}
309
- ) ;
303
+ }
304
+ } ) ;
310
305
}
311
306
312
307
private setBackdrop ( setBackdrop : boolean ) : void {
313
- 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) ;
314
311
}
315
312
316
313
private setBodyStyles ( open : boolean ) : void {
0 commit comments