Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/dialog): provide defaults for dialog animation #24591

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/material/dialog/dialog-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import {
group,
} from '@angular/animations';

/**
* Default parameters for the animation for backwards compatibility.
* @docs-private
*/
export const defaultParams = {
params: {enterAnimationDuration: '150ms', exitAnimationDuration: '75ms'},
};

/**
* Animations used by MatDialog.
* @docs-private
Expand All @@ -40,13 +48,15 @@ export const matDialogAnimations: {
),
query('@*', animateChild(), {optional: true}),
]),
defaultParams,
),
transition(
'* => void, * => exit',
group([
animate('{{exitAnimationDuration}} cubic-bezier(0.4, 0.0, 0.2, 1)', style({opacity: 0})),
query('@*', animateChild(), {optional: true}),
]),
defaultParams,
),
]),
};
5 changes: 3 additions & 2 deletions src/material/dialog/dialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {ViewContainerRef, ComponentFactoryResolver} from '@angular/core';
import {Direction} from '@angular/cdk/bidi';
import {ScrollStrategy} from '@angular/cdk/overlay';
import {defaultParams} from './dialog-animations';

/** Options for where to set focus to automatically on dialog open */
export type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading';
Expand Down Expand Up @@ -127,10 +128,10 @@ export class MatDialogConfig<D = any> {
componentFactoryResolver?: ComponentFactoryResolver;

/** Duration of the enter animation. Has to be a valid CSS value (e.g. 100ms). */
enterAnimationDuration?: string = '150ms';
enterAnimationDuration?: string = defaultParams.params.enterAnimationDuration;

/** Duration of the exit animation. Has to be a valid CSS value (e.g. 50ms). */
exitAnimationDuration?: string = '75ms';
exitAnimationDuration?: string = defaultParams.params.exitAnimationDuration;

// TODO(jelbourn): add configuration for lifecycle hooks, ARIA labelling.
}
8 changes: 5 additions & 3 deletions src/material/dialog/dialog-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import {matDialogAnimations} from './dialog-animations';
import {matDialogAnimations, defaultParams} from './dialog-animations';
import {MatDialogConfig} from './dialog-config';

/** Event that captures the state of dialog container animations. */
Expand Down Expand Up @@ -365,8 +365,10 @@ export class MatDialogContainer extends _MatDialogContainerBase {
return {
value: this._state,
params: {
enterAnimationDuration: this._config.enterAnimationDuration || '150ms',
exitAnimationDuration: this._config.exitAnimationDuration || '75ms',
enterAnimationDuration:
this._config.enterAnimationDuration || defaultParams.params.enterAnimationDuration,
exitAnimationDuration:
this._config.exitAnimationDuration || defaultParams.params.exitAnimationDuration,
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/material/dialog/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export * from './dialog-container';
export * from './dialog-content-directives';
export * from './dialog-config';
export * from './dialog-ref';
export * from './dialog-animations';
export {matDialogAnimations} from './dialog-animations';