Angular Animation not smoothly transitioning on Internet Explorer 11 and Firefox, but functioning correctly on Chrome

Chrome seems to be handling my Angular animation attached to a div (where the height goes from 0 to '*') just fine. I've made sure to import all necessary polyfills and install web-animations-js.

However, when it comes to IE and Firefox, there's an issue - the height increases but there is no smooth transition for the animation.

Here's a snippet of the animations.ts file:

import {
  trigger,
  state,
  style,
  transition,
  animate
} from "@angular/animations";

export const Animations = {
  animations: [
    trigger("expansionTrigger", [
      state(
        "true",
        style({
          height: "*",
          display: "inline-block",
          width: "100%",
          overflow: "hidden"
        })
      ),
      state(
        "false",
        style({
          height: "0",
          display: "none",
          padding: "0",
          overflow: "hidden"
        })
      ),
      transition("true => false", animate("1s 100ms ease-out")),
      transition("false => true", animate("1s ease-in"))
    ]),
    trigger("fadeInTrigger", [
      state(
        "true",
        style({
          opacity: "1"
        })
      ),
      state(
        "false",
        style({
          opacity: "0"
        })
      ),
      transition("true => false", animate("1s ease")),
      transition("false => true", animate("1s 300ms ease"))
    ])
  ]
};

In the content.component.html file, we have:

<div
[@expansionTrigger]="isExpanded === 'true' ? 'true' : 'false'"
[@fadeInTrigger]="isExpanded === 'true' ? 'true' : 'false'"
class="ds-u-sans">
    <div class="padding-20">
        <ng-content></ng-content>
    </div>
</div>

And in content.component.ts:

import { Component } from '@angular/core';
import { Animations } from '../animations'

@Component({
  selector: 'app-accordion-content',
  templateUrl: './accordion-content.component.html',
  styleUrls: ['./accordion-content.component.css'],
  animations: [
    Animations.animations
  ]
})
export class AccordionContentComponent  {
  isExpanded: string = "false";

}

Answer №1

If you're still searching for a solution or looking for some assistance with your specific problem, I might have a suggestion that could be of help. I encountered a similar issue in the past and managed to resolve it by explicitly defining properties like marginTop / paddingBottom instead of using shorthand properties like margin / padding.

A useful comment on Angular Issue #16330 (link here) guided me towards this approach.

Even though your concern is related to height, the presence of a shorthand padding property in your "false" state could potentially be causing compatibility issues with Edge and Firefox.

For instance, rather than:

state(
  "false",
  style({
    height: "0",
    display: "none",
    padding: "0",       <------
    overflow: "hidden"
  })
)

You may want to consider trying:

state(
  "false",
  style({
    height: "0",
    display: "none",
    paddingTop: "0",    <------
    paddingBottom: "0", <------
    overflow: "hidden"
  })
)

In addition, keep in mind that display:none can sometimes affect animations unexpectedly. There might be limitations when transitioning between display: inline-block and display: none, resulting in peculiar behavior as explained here.

Instead of using "true" and "false" states, you could try employing '*' and 'void' combined with an *ngIf directive in your template if suitable for your project. This might require some adjustments but can provide more control over element visibility compared to CSS properties like display.

Check out the 'void' state documentation and further clarification on 'void' under Parameters > name in Angular's official resources for more details.

I hope these insights are helpful in addressing your issue. They proved beneficial for me in resolving similar concerns, so I'm hopeful they'll offer guidance to others facing similar challenges.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating an object efficiently by defining a pattern

As a newcomer to Typescript (and Javascript), I've been experimenting with classes. My goal is to create an object that can be filled with similar entries while maintaining type safety in a concise manner. Here is the code snippet I came up with: le ...

Asynchronous requests from clients paired with server-side rendering

Exploring the realm of SEO with Angular4/Node.js has presented a unique challenge for me. Utilizing Angular Universal allows for server-side rendering, enabling me to inject meta keywords, title, and image URLs into the HTML before it reaches the browser. ...

Having trouble resolving the error "Cannot find name CSSTranslate" while working with VSCode and tsc? Let's tackle this issue together

My program runs smoothly in a development environment and appears flawless in VSCode, but I'm encountering issues with tsc pointing out unknown names and properties. It's puzzling because my file doesn't seem to have any problems in VSCode. ...

Guide on utilizing the express server in developer mode within the Angular 17 application development tool

The guidelines provided in the documentation () explain that: Angular CLI will generate an initial server setup specifically for rendering your Angular application on the server side. This server can be customized to handle additional functionalities lik ...

The mat dialog is displayed with a mat table below the title line

Is there a solution for the issue where the mat-table in a mat dialog displays a line below the heading? This is the code snippet: <h2 mat-dialog-title>dialog title</h2> <mat-dialog-content class="mat-typography"> <div c ...

Angular calendar module for easy scheduling

I am currently utilizing the angular full calendar day grid plugin. The format of my json data is as follows: [ {“id”:2,“start_time”:“2019-08-15 16:52:00”}, {“id”:3, “start_time”:“2019-09-23 18:55:00”} ] Unfortunately, angular f ...

What is the best way to implement forwardRef in a distinct select component?

Currently, I am utilizing react, typescript, and styled-components to work on my project. Specifically, I am aiming to create a select component for use in React Hook Form. Initially, everything seemed to be in order, but I encountered an error from typesc ...

Angular 2's Stylish Modal Boxes

I've been trying to integrate the fancybox package into my Angular 2 application. I installed it using npm and carefully went through the documentation. However, I encountered an issue where fancybox is not working as expected. Initially, I suspected ...

Adjusting the height of content in Angular Material 2 md-tab

I've recently started working with angular material and I'm facing an issue while trying to implement md-tab into my application. The problem is that I can't seem to style my tab content to take up the remaining height of the screen. Could s ...

Can we restrict type T to encompass subclasses of K, excluding K itself?

Can a generic type T be restricted to the subset of subtypes of type K, excluding K itself? I am attempting to define a type for inheritance-based mixin functions. An answer for the opposite case is provided in Question 32488309, and interestingly, this qu ...

Necessary CSS selector input equivalent in Reactive Forms

Is there a similar CSS method like input:required {CSS} to style all the reactive form fields in Angular that are set as required using Validators.required in their formControl? Or is there another approach to achieve this with CSS? ...

What is the best way to iterate through the result of an HTTP request in Angular 11?

I am a beginner with Angular and currently working in Angular 11. I am facing issues with making an http request. Despite going through numerous Stack Overflow posts, none of the solutions seem to work for me, even though some questions are similar to mine ...

Struggling to connect the array of objects from the .ts file with the template (.html) in Angular

Inside this .ts file, I am populating the "mesMenus" array that I want to display in the .html file: export class MenusComponent{ mesMenus= new Array<Menu>(); constructor(private gMenuService:GestionMenuService){ this.gMenuService.onAdd ...

Typescript or Angular 2 for Google Maps

Is there a way to integrate Google Maps Javascript API with Typescript or Angular 2? Although libraries like https://github.com/SebastianM/angular2-google-maps are available, they may not provide full support for features like Events and Places Libraries ...

How can I test for equality with an array item using v-if in Vue.js?

Currently, I am facing a challenge in my Vue.js project where I need to determine if a number is equal to an element within an array. Here is the code snippet that I am working with: <div v-if="someValue != arrayElement"> // </div> I am st ...

ViewContainerRef fails to render component on the DOM

@Component({ selector: 'my-cmp', template: ` <div #target></div> ` }) export class MyCmp { @ViewChild('target', {read: ViewContainerRef}) target : ViewContainerRef; render() { let component = createComponent(met ...

Leveraging the keyof keyword to access a specific property within a type

I have a variety of types that I need to work with. For example: type Type = { prop1: number; prop2: string; prop3: someOtherType } type Props = keyof Type I am aware that using an "indexed access type" allows me to extract the type of propN, ...

What is the best approach for managing and obtaining accurate JSON responses when working with PHP API and AngularJS 2 services?

Encountering a backend issue with MySQL, wherein one query is producing a specific dataset: {"candidat":[{"ID":1,"nom":"Danny","prenom":"Hariot","parti":"Quamba","departement":"Ukraine","commune":"Chapayeve"},{"ID":2,"nom":"Shari","prenom":"Adamkiewicz"," ...

react-vimeo not firing onPause and onPlay events

I am facing an issue with triggering props when playing a Vimeo video on my webpage. Here's a snippet of my code: import Vimeo from '@u-wave/react-vimeo'; const handleVimeoProgress = (data: any) => { console.log('Progress:' ...

How to outsmart the TypeScript compiler when integrating a library without type definitions?

Is there a way to deceive the compiler into thinking that certain definitions are being used? My constructor contains: nv.addGraph(()=> {...}) Before my class declaration, I include: public nv:nv; In my model file, I define: export interface nv{ ...