-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Description
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
I am trying to convert our application to use the new Angular CSS animations. I love the idea and simple animations convert across very easily. Single use animations are also simply converted. The new animations are extremely elegant.
I have an issue with more complex re-usable animations though, specifically those that use AUTO_STYLE (I do know about the grid CSS trick).
Here is a simple example of an animation used everywhere in our application. It simply expands an inline element, pushing other inline content to the right as it expands. We have many other animations that also use AUTO_STYLE for them to work.
export const horizontalExpandAnimation: AnimationTriggerMetadata = trigger('horizontalExpandAnimation', [
transition(
':enter',
[
style({ transform: 'scaleX(0)', width: 0, 'transform-origin': 'left' }),
animate('{{ time }} ease-in-out', style({ transform: 'scaleX(100%)', width: AUTO_STYLE }))
],
{ params: { time: '250ms' } }
),
transition(
':leave',
[
style({ transform: 'scaleX(100%)', 'transform-origin': 'left' }),
animate('{{ time }} ease-in-out', style({ transform: 'scaleX(0)', width: 0 }))
],
{ params: { time: '250ms' } }
)
]);
This can be replicated using CSS grid with 0fr to 1fr animation. However for this to work, i need two elements - the parent with the grid styling and the content that is being animated.
So my two options currently are:
- Create a component that does the animation. This is a bit messy as now i need to add an additional component that wraps the various many elements that can be expanded.
- Implicitly "know" that this animation type only works as a direct child of a specific class that i need to apply to the parent element.
Both of these options are not as elegant as putting @horizontalExpandAnimation
on the element i want to expand.
Maybe I've missed something here as information is a bit sparse (understandably so as 20.2 is quite young) and the examples everyone provides are simplistic. I'm always happy to be told I'm wrong :)
Proposed solution
Could we have an animate.enter and .leave events include a copy of the content that angular is about to render in to the DOM so i can measure it?
I tried reading target
in the enter event but this is provided without any children content, so is always width 0.
Alternatives considered
None that i can think of.