-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[Dialog] Allow customization of open/close animations #8857
Comments
This should actually be implemented to all components that use animations. A consistent way to override animations: by default provide animations that comply with material spec, but let developers override those with custom ones. |
This is a very useful feature , it will be great if we can add the support. |
This would be an extremely nice feature. I've hit a fork in the road with a project because I need much more flexibility out of material for simple things such as which direction a dialog flys out from. I am reading about the CDK which is pretty light right now, but it seems to offer something. I am just not sure yet (heavily lacking in documentation). The other option I see is to use the NoopAnimationsModule which kills the animation completely but that doesn't seem to get me anywhere either. It's an all or nothing thing. It doesn't look like you can do it on a per-component-basis. |
We are looking forward to have this feature available. |
Since there is no way (yet) to override animations officially, there is always dirty hack that will allow you to do that (example is for MatMenu, but works for other elements): import { MatMenu } from '@angular/material';
import {
animate,
state,
style,
transition,
trigger
} from '@angular/animations';
MatMenu['decorators'][0].args[0].animations[0] = trigger('transformMenu', [
state('void', style({
opacity: 0,
transform: 'scale(0, 0)'
})),
state('enter-start', style({
opacity: 0,
transform: 'scale(0, 0)'
})),
state('enter', style({
opacity: 1,
transform: 'scale(1, 1)'
})),
transition('void => enter-start', animate('0ms ease-in-out')),
transition('enter-start => enter', animate('300ms ease-in-out')),
transition('* => void', animate('300ms ease-in-out', style({ opacity: 0 })))
]); This code for example, replaces one of two angular-animations of MatMenu element, dropdown show/hide animation. But coupled with property checks it can be quite long-living solution. To find needed animation's name and its states, you can to go to the source (in my case |
I also need the ability to edit the animations on a dialog. Please make this configurable. @omieliekh I tried your code but couldn't get it to work for MatDialog. I see what you referenced in Can you share how you did that? |
@chipallen2 sorry for frustration caused, unfortunately my code is not working on production 🙁 |
You can try to override material classes. This slides down the dialog. @Keyframes slideDown{ .cdk-overlay-pane{ You can see it in action here: https://angular-je6ade.stackblitz.io |
@carvarr it works great to customize the show animation, but how can we customize the hide animation? |
so custom animation working on dialogs? i dont see it yet working. can anyone pplease clarify final status of this issue? |
Upvoting this feature. @carvarr 's suggestion works nicely for animating dialog entry. @omieliekh 's solution allows full customization of the dialog animations, however this always applies globally to all dialogs and I could not get this solution to work only on one instance of a material dialog. |
Any news on that one? Will that become available? |
@omieliekh 's solution doesn't work on --prod, or did i miss something? |
My work around based on solution of @omieliekh, no error on build --prod, it is working for the wait of the feature release. `export interface AnimationDefination { export type RedefinedAnimationCallback = (AnimationDefination) => AnimationDefination; export class ComponentDependentAnimationDriver extends ɵWebAnimationsDriver {
}` In app modules
|
sorry, but could you fix your typo in |
Unfortunately this solution never got past ”ng serve”, so I can’t say whether it would work with minified code or not. Still waiting for official solution, before applying custom animations to production code. |
would be nice to have this |
Upvote |
Any updates on this? |
Angular material is super slow. Tried all workarounds but none is working. |
For MatDialog it's in here: |
My custom dialog service, with animation and more. |
When will the CDKDialog be released? |
works in chrome and firefox but does not work in safari |
So the way I worked around this was to add a panel-class to the dialog then set up custom animation for that dialog. global scss file
custom dialog button component
|
Can someone advise what is a good way to disable background page refresh animation while doing a retry on an open mat dialog component? |
Ok, the question is that when the /**
* Animates an overlaid mat dialog on close.
*/
export function fadeOut() {
const overlays = document.getElementsByClassName('my-overlay');
for (let i = 0; i < overlays.length; i++) {
overlays[overlays.length - 1].animate([
{ transform: 'scale(1, 1)' },
{ transform: 'scale(0, 0)' }
], { duration: 400, iterations: 1 });
}
} This function is imported and called when I click on Maybe this is one of the worst ways to solve the issue but I didn't want to install the |
In Angular latest version I was able to with keyframeAnimationOptions.
|
@rajesh05c4 where in the angular project did you use these keyframeAnimationOptions? In which class? |
Your solution works, thanks. |
Our solution to this is to use .custom-mat-dialog-panel {
.mat-dialog-container {
animation: dialog-animation;
}
}
// If you want to customise the backdrop animation
.custom-mat-dialog-backdrop {
transition: none;
animation: backdrop-animation;
} However this caused another problem - because no angular animations were playing, if a dialog was opened from MatMenu, then MatMenu would steal focus away from the dialog (focussing the trigger element). I believe this is because when using angular animations, the dialog doesn't capture focus until after the animations finish, which is also after MatMenu has set focus. We managed to work around this by telling the dialog to recapture focus: const ref = this.dialog.open(...);
ref.afterOpened().subscribe(() => {
setTimeout(() => {
ref._containerInstance._recaptureFocus();
});
}); If you abstract opening of dialogs into a service then this only needs to be done once. Another workaround is to call |
Any updates on this or do we still need to use the workarounds mentioned? 😞 |
We're in the process of cleaning up our issue backlog. Unfortunately I'll have to close this issue, because the Material dialog uses the
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
feature
What is the expected behavior?
When open or close dialog,animation should define by developer.
What is the current behavior?
I found that open and close dialog
<mat-dialog-container></mat-dialog-container>
will add classng-animating
,well open will add once and remove within a short time period(less than 0.5s),but in my case,open and close will use different animation,so it doesn't work for me to overwrite.ng-animating
What is the use-case or motivation for changing an existing behavior?
Add different animation in open and close dialog.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular: 5.0.0,
Material: 5.0.0-rc0,
OS: win10,
TypeScript: 2.6.1,
Browsers: Chrome@62.0.3202.94
The text was updated successfully, but these errors were encountered: