5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { Injector , ViewContainerRef } from '@angular/core' ;
8
+
9
+ import {
10
+ ViewContainerRef ,
11
+ ComponentFactoryResolver ,
12
+ Injector ,
13
+ StaticProvider ,
14
+ Type ,
15
+ } from '@angular/core' ;
9
16
import { Direction } from '@angular/cdk/bidi' ;
10
- import { ComponentType } from '@angular/cdk/overlay' ;
11
- import { CdkDialogContainer } from './dialog-container ' ;
17
+ import { PositionStrategy , ScrollStrategy } from '@angular/cdk/overlay' ;
18
+ import { BasePortalOutlet } from '@angular/cdk/portal ' ;
12
19
13
20
/** Options for where to set focus to automatically on dialog open */
14
21
export type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading' ;
15
22
16
- /** Valid ARIA roles for a dialog element. */
17
- export type DialogRole = 'dialog' | 'alertdialog' ;
18
-
19
- /** Possible overrides for a dialog's position. */
20
- export interface DialogPosition {
21
- top ?: string ;
22
- bottom ?: string ;
23
- left ?: string ;
24
- right ?: string ;
25
- }
26
-
27
- export class DialogConfig < D = any > {
28
- /** Component to use as the container for the dialog. */
29
- containerComponent ?: ComponentType < CdkDialogContainer > ;
30
-
23
+ /** Configuration for opening a modal dialog. */
24
+ export class DialogConfig < D = any , R = any , C extends BasePortalOutlet = BasePortalOutlet > {
31
25
/**
32
26
* Where the attached component should live in Angular's *logical* component tree.
33
27
* This affects what is available for injection and the change detection order for the
@@ -42,55 +36,61 @@ export class DialogConfig<D = any> {
42
36
*/
43
37
injector ?: Injector ;
44
38
45
- /** The id of the dialog. */
39
+ /** ID for the dialog. If omitted, a unique one will be generated . */
46
40
id ?: string ;
47
41
48
- /** The ARIA role of the dialog. */
49
- role ?: DialogRole = 'dialog' ;
42
+ /** The ARIA role of the dialog element. */
43
+ role ?: string = 'dialog' ;
44
+
45
+ /** Whether this a modal dialog. */
46
+ isModal ?: boolean = true ;
50
47
51
- /** Custom class(es) for the overlay panel . */
48
+ /** Custom class for the overlay pane . */
52
49
panelClass ?: string | string [ ] = '' ;
53
50
54
- /** Whether the dialog has a background . */
51
+ /** Whether the dialog has a backdrop . */
55
52
hasBackdrop ?: boolean = true ;
56
53
57
- /** Custom class(es) for the backdrop. */
58
- backdropClass ?: string | undefined = '' ;
54
+ /** Custom class for the backdrop. */
55
+ backdropClass ?: string | string [ ] = '' ;
59
56
60
- /** Whether the dialog can be closed by user interaction . */
57
+ /** Whether the user can use escape or clicking on the backdrop to close the modal . */
61
58
disableClose ?: boolean = false ;
62
59
63
- /** The width of the dialog. */
60
+ /** Width of the dialog. */
64
61
width ?: string = '' ;
65
62
66
- /** The height of the dialog. */
63
+ /** Height of the dialog. */
67
64
height ?: string = '' ;
68
65
69
- /** The minimum width of the dialog. */
70
- minWidth ?: string | number = '' ;
66
+ /** Min- width of the dialog. If a number is provided, assumes pixel units . */
67
+ minWidth ?: number | string ;
71
68
72
- /** The minimum height of the dialog. */
73
- minHeight ?: string | number = '' ;
69
+ /** Min- height of the dialog. If a number is provided, assumes pixel units . */
70
+ minHeight ?: number | string ;
74
71
75
- /** The maximum width of the dialog. */
76
- maxWidth ?: string | number = '80vw' ;
72
+ /** Max- width of the dialog. If a number is provided, assumes pixel units. Defaults to 80vw . */
73
+ maxWidth ?: number | string ;
77
74
78
- /** The maximum height of the dialog. */
79
- maxHeight ?: string | number = '' ;
75
+ /** Max- height of the dialog. If a number is provided, assumes pixel units . */
76
+ maxHeight ?: number | string ;
80
77
81
- /** The position of the dialog. */
82
- position ?: DialogPosition ;
78
+ /** Strategy to use when positioning the dialog. Defaults to centering it on the page . */
79
+ positionStrategy ?: PositionStrategy ;
83
80
84
- /** Data to be injected into the dialog content . */
81
+ /** Data being injected into the child component . */
85
82
data ?: D | null = null ;
86
83
87
- /** The layout direction for the dialog content. */
84
+ /** Layout direction for the dialog's content. */
88
85
direction ?: Direction ;
89
86
90
87
/** ID of the element that describes the dialog. */
91
88
ariaDescribedBy ?: string | null = null ;
92
89
93
- /** Aria label to assign to the dialog element */
90
+ /** ID of the element that labels the dialog. */
91
+ ariaLabelledBy ?: string | null = null ;
92
+
93
+ /** Aria label to assign to the dialog element. */
94
94
ariaLabel ?: string | null = null ;
95
95
96
96
/**
@@ -100,9 +100,48 @@ export class DialogConfig<D = any> {
100
100
*/
101
101
autoFocus ?: AutoFocusTarget | string | boolean = 'first-tabbable' ;
102
102
103
- /** Duration of the enter animation. Has to be a valid CSS value (e.g. 100ms). */
104
- enterAnimationDuration ?: string = '225ms' ;
103
+ /**
104
+ * Whether the dialog should restore focus to the
105
+ * previously-focused element, after it's closed.
106
+ */
107
+ restoreFocus ?: boolean = true ;
108
+
109
+ /** Scroll strategy to be used for the dialog. */
110
+ scrollStrategy ?: ScrollStrategy ;
111
+
112
+ /**
113
+ * Whether the dialog should close when the user goes backwards/forwards in history.
114
+ * Note that this usually doesn't include clicking on links (unless the user is using
115
+ * the `HashLocationStrategy`).
116
+ */
117
+ closeOnNavigation ?: boolean = true ;
118
+
119
+ /** Alternate `ComponentFactoryResolver` to use when resolving the associated component. */
120
+ componentFactoryResolver ?: ComponentFactoryResolver ;
121
+
122
+ /**
123
+ * Providers that will be exposed to the contents of the dialog. Can also
124
+ * be provided as a function in order to generate the providers lazily.
125
+ */
126
+ providers ?:
127
+ | StaticProvider [ ]
128
+ | ( ( dialogRef : R , config : DialogConfig < D > , container : C ) => StaticProvider [ ] ) ;
105
129
106
- /** Duration of the exit animation. Has to be a valid CSS value (e.g. 50ms). */
107
- exitAnimationDuration ?: string = '225ms' ;
130
+ /**
131
+ * Component into which the dialog content will be rendered. Defaults to `CdkDialogContainer`.
132
+ * A configuration object can be passed in to customize the providers that will be exposed
133
+ * to the dialog container.
134
+ */
135
+ container ?:
136
+ | Type < C >
137
+ | {
138
+ type : Type < C > ;
139
+ providers : ( config : DialogConfig < D > ) => StaticProvider [ ] ;
140
+ } ;
141
+
142
+ /**
143
+ * Context that will be passed to template-based dialogs.
144
+ * A function can be passed in to resolve the context lazily.
145
+ */
146
+ templateContext ?: Record < string , any > | ( ( ) => Record < string , any > ) ;
108
147
}
0 commit comments