Skip to content

Commit 9d805f7

Browse files
crisbetoannieyw
authored andcommitted
refactor(material/dialog): use type overload for open method (#11731)
* Reworks the `MatDialog.open` method to use overloads, rather than the single signature that has `componentOrTemplateRef: ComponentType<T> | TemplateRef<T>`. This makes the separation clearer and looks nicer in autocompletion. * Adds docs for the `MatBottomSheet.open` method. (cherry picked from commit 70e9eb9)
1 parent 695b84f commit 9d805f7

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/material/bottom-sheet/bottom-sheet.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,21 @@ export class MatBottomSheet implements OnDestroy {
6262
@Optional() @Inject(MAT_BOTTOM_SHEET_DEFAULT_OPTIONS)
6363
private _defaultOptions?: MatBottomSheetConfig) {}
6464

65+
/**
66+
* Opens a bottom sheet containing the given component.
67+
* @param component Type of the component to load into the bottom sheet.
68+
* @param config Extra configuration options.
69+
* @returns Reference to the newly-opened bottom sheet.
70+
*/
6571
open<T, D = any, R = any>(component: ComponentType<T>,
6672
config?: MatBottomSheetConfig<D>): MatBottomSheetRef<T, R>;
73+
74+
/**
75+
* Opens a bottom sheet containing the given template.
76+
* @param template TemplateRef to instantiate as the bottom sheet content.
77+
* @param config Extra configuration options.
78+
* @returns Reference to the newly-opened bottom sheet.
79+
*/
6780
open<T, D = any, R = any>(template: TemplateRef<T>,
6881
config?: MatBottomSheetConfig<D>): MatBottomSheetRef<T, R>;
6982

src/material/dialog/dialog.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,27 @@ export abstract class _MatDialogBase<C extends _MatDialogContainerBase> implemen
116116

117117
/**
118118
* Opens a modal dialog containing the given component.
119-
* @param componentOrTemplateRef Type of the component to load into the dialog,
120-
* or a TemplateRef to instantiate as the dialog content.
119+
* @param component Type of the component to load into the dialog.
121120
* @param config Extra configuration options.
122121
* @returns Reference to the newly-opened dialog.
123122
*/
124-
open<T, D = any, R = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
125-
config?: MatDialogConfig<D>): MatDialogRef<T, R> {
123+
open<T, D = any, R = any>(component: ComponentType<T>,
124+
config?: MatDialogConfig<D>): MatDialogRef<T, R>;
125+
126+
/**
127+
* Opens a modal dialog containing the given template.
128+
* @param template TemplateRef to instantiate as the dialog content.
129+
* @param config Extra configuration options.
130+
* @returns Reference to the newly-opened dialog.
131+
*/
132+
open<T, D = any, R = any>(template: TemplateRef<T>,
133+
config?: MatDialogConfig<D>): MatDialogRef<T, R>;
126134

135+
open<T, D = any, R = any>(template: ComponentType<T> | TemplateRef<T>,
136+
config?: MatDialogConfig<D>): MatDialogRef<T, R>;
137+
138+
open<T, D = any, R = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
139+
config?: MatDialogConfig<D>): MatDialogRef<T, R> {
127140
config = _applyConfigDefaults(config, this._defaultOptions || new MatDialogConfig());
128141

129142
if (config.id && this.getDialogById(config.id) &&

tools/public_api_guard/material/dialog.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export declare abstract class _MatDialogBase<C extends _MatDialogContainerBase>
99
closeAll(): void;
1010
getDialogById(id: string): MatDialogRef<any> | undefined;
1111
ngOnDestroy(): void;
12-
open<T, D = any, R = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>, config?: MatDialogConfig<D>): MatDialogRef<T, R>;
12+
open<T, D = any, R = any>(component: ComponentType<T>, config?: MatDialogConfig<D>): MatDialogRef<T, R>;
13+
open<T, D = any, R = any>(template: TemplateRef<T>, config?: MatDialogConfig<D>): MatDialogRef<T, R>;
14+
open<T, D = any, R = any>(template: ComponentType<T> | TemplateRef<T>, config?: MatDialogConfig<D>): MatDialogRef<T, R>;
1315
static ɵdir: i0.ɵɵDirectiveDefWithMeta<_MatDialogBase<any>, never, never, {}, {}, never>;
1416
static ɵfac: i0.ɵɵFactoryDef<_MatDialogBase<any>, never>;
1517
}

0 commit comments

Comments
 (0)