Skip to content

Commit 4ad7cc8

Browse files
crisbetojelbourn
authored andcommitted
chore(snack-bar): allow stronger typing for config data (#9408)
* Along the same lines as the dialog data, adds a generic param to the `MatSnackBarConfig` that allows consumers to type the `data` property. * Adds a couple of missing docstrings to the `MAT_DIALOG_DATA` and `MAT_SNACK_BAR_DATA`.
1 parent d0ad3b7 commit 4ad7cc8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/lib/dialog/dialog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {MatDialogConfig} from './dialog-config';
3535
import {MatDialogContainer} from './dialog-container';
3636
import {MatDialogRef} from './dialog-ref';
3737

38-
38+
/** Injection token that can be used to access the data that was passed in to a dialog. */
3939
export const MAT_DIALOG_DATA = new InjectionToken<any>('MatDialogData');
4040

4141
/** Injection token that can be used to specify default dialog options. */

src/lib/snack-bar/snack-bar-config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {ViewContainerRef, InjectionToken} from '@angular/core';
1010
import {AriaLivePoliteness} from '@angular/cdk/a11y';
1111
import {Direction} from '@angular/cdk/bidi';
1212

13+
/** Injection token that can be used to access the data that was passed in to a snack bar. */
1314
export const MAT_SNACK_BAR_DATA = new InjectionToken<any>('MatSnackBarData');
1415

1516
/** Possible values for horizontalPosition on MatSnackBarConfig. */
@@ -21,7 +22,7 @@ export type MatSnackBarVerticalPosition = 'top' | 'bottom';
2122
/**
2223
* Configuration used when opening a snack-bar.
2324
*/
24-
export class MatSnackBarConfig {
25+
export class MatSnackBarConfig<D = any> {
2526
/** The politeness level for the MatAriaLiveAnnouncer announcement. */
2627
politeness?: AriaLivePoliteness = 'assertive';
2728

@@ -41,13 +42,13 @@ export class MatSnackBarConfig {
4142
* Extra CSS classes to be added to the snack bar container.
4243
* @deprecated Use `panelClass` instead.
4344
*/
44-
extraClasses?: string | string[];
45+
extraClasses?: string | string[];
4546

4647
/** Text layout direction for the snack bar. */
4748
direction?: Direction = 'ltr';
4849

4950
/** Data being injected into the child component. */
50-
data?: any = null;
51+
data?: D | null = null;
5152

5253
/** The horizontal position to place the snack bar. */
5354
horizontalPosition?: MatSnackBarHorizontalPosition = 'center';

0 commit comments

Comments
 (0)