Skip to content

Commit 05c29df

Browse files
committed
refactor(dialog): use type overload for open method
* 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.
1 parent 09dc459 commit 05c29df

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

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

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

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

src/material/dialog/dialog.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,22 @@ export class MatDialog implements OnDestroy {
115115

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

tools/public_api_guard/material/dialog.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export declare class MatDialog implements OnDestroy {
3333
closeAll(): void;
3434
getDialogById(id: string): MatDialogRef<any> | undefined;
3535
ngOnDestroy(): void;
36-
open<T, D = any, R = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>, config?: MatDialogConfig<D>): MatDialogRef<T, R>;
36+
open<T, D = any, R = any>(component: ComponentType<T>, config?: MatDialogConfig<D>): MatDialogRef<T, R>;
37+
open<T, D = any, R = any>(template: TemplateRef<T>, config?: MatDialogConfig<D>): MatDialogRef<T, R>;
3738
static ɵfac: i0.ɵɵFactoryDef<MatDialog>;
3839
static ɵprov: i0.ɵɵInjectableDef<MatDialog>;
3940
}

0 commit comments

Comments
 (0)