This is a bit of a workaround, but it will at least make a similar looking animation in IE/Edge. It's similar, but not identical, and it doesn't have any overflow issues.
it turns out that this is an Angular issue. it attempts to translate the animation code to CSS @keyframes
for browser that do not support WebAnimations
and the overflow-y
property doesn't seem to translate properly.
Since we know what isn't supported, we can detect support for the API and switch out which animation to use based on that. The line 'animate' in document.documentElement
will tell us if WebAnimations
are supported or not.
Here's the full code:
import { trigger, transition, style, animate, state, AnimationMetadata } from '@angular/animations';
import { defaultDuration, defaultEasing } from './animation-variables';
//Angular does not properly translate a WebAnimation with `overflow-y` into a CSS Animation, this it overflows it's container.
//So we use an entirely different animation for these browsers. It will still overflow, but the added opacity transition makes it less obvious
const animForWebAnimations: AnimationMetadata[] = [
state('*', style({
height: '*',
})),
state('void', style({
height: '0',
'overflow-y': 'hidden',
})),
//Same transition duration/easing when entering or leaving
transition('* => *', animate(`${defaultDuration}ms ${defaultEasing}`))
];
const animForCssAnimations: AnimationMetadata[] = [
state('*', style({
height: '*',
'transform-origin': 'center 0',
transform: 'scaleY(1)'
})),
state('void', style({
height: '0px',
'transform-origin': 'center 0',
transform: 'scaleY(0)'
})),
transition('* => *', animate(`${defaultDuration}ms ${defaultEasing}`))
];
const expandCollapseAnimationMetadata = 'animate' in document.documentElement ? animForWebAnimations : animForCssAnimations;
export const expandCollapseAnimation = trigger('expandCollapse', expandCollapseAnimationMetadata);
For Chrome/Firefox and other "good" browsers the animation looks the same as above in my question, but now it looks like this in IE/Edge
