Skip to content

BrowserAnimationsModule changes the behaviour of select-dropdowns #18430

Closed

Description

@tobias74

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

It is rather complicated to sum up the situation, here is my SO-Posting on the matter:
https://stackoverflow.com/questions/45420803/browseranimationsmodule-altering-behaviour-of-select-dropdowns

Basically, when I programmatically remove an option form a dropdown, I dont want the selection to change. In case the select-dropdown is pristine, removing an option will cause the select to display the first option as the selected one:
Here is the defective plunkr:
https://plnkr.co/edit/ayzM2HNtO6Hkkr8jkgVA?p=preview

Expected behavior

I dont think the selection of a pristine select should change, when an option is removed programmatically. Here is a working plunkr:
https://plnkr.co/edit/dPDpEQm14pWlFNfLe4nP?p=preview

Now the thin is, the only difference between defective and working plunkr is that in the working plunkr I have remove the BrowserAnimationsModule from the Module-Imports (at the bottom of the file, I did keep the ts-import )

This makes it seem that the BrowserAnimaitonsModule is somehow responsible for changing the behaviour of the select-dropdown.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Angular version: 4.3.2


Browser:
- [x ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ x] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Activity

  1. added
    area: animations
    on Jul 31, 2017
  2. matsko commented on Oct 31, 2017

    @matsko
    Contributor

    So to verify, the dropdown's selected value flips to 1 when BrowserAnimationsModule is present (otherwise it stays selected as is) correct?

  3. tobias74 commented on Nov 5, 2017

    @tobias74
    Author

    Correct, the value flips. Removing the BrowserAnimationsModule solves the issue. Using a third-party-select like the angular/material-select dos not show the issue.

  4. YounesM commented on Dec 21, 2017

    @YounesM

    The value doesn't flip as the model stays empty. It only displays an element as selected where none are. Here is another defective example : https://stackblitz.com/edit/angular-pjrg1p

    A simple workaround is to add animations: [ trigger('',[])] to your components.

    @Component({
      animations: [trigger('', [])],
      selector: 'my-app',
      templateUrl: 'app.component.html',
      styleUrls: ['app.component.scss']
    })
    
  5. added this to the Backlog milestone on Jan 23, 2018
  6. tobias74 commented on Oct 30, 2018

    @tobias74
    Author

    I have made a stackblitz for this bug, since the original plunkr-exmaple does not load anymore:
    https://stackblitz.com/edit/angular-animations-dropdown-bug

    (Using angular 7.0.1)

  7. FritzHerbers commented on Mar 1, 2019

    @FritzHerbers

    I am having a problem with BrowserAnimationsModule (by just loading it/not using it), ngx-formly and selects.
    When options are loaded a second time and there is no model for a select, the first option is choosen.

    See https://stackblitz.com/edit/angular-sg8rfv?file=src%2Fapp%2Fapp.module.ts with the steps to reproduce.

    Since Jan 23, 2018 this issue is moved to the backlog, will it be checked again by occasion?

  8. theodorejb commented on Nov 8, 2019

    @theodorejb
    Contributor

    I spent a lot of time debugging before I figured out that this issue was caused by the presence of BrowserAnimationsModule. Here's a simple demo illustrating the bug in Angular 8: https://stackblitz.com/edit/angular-bam-select-bug?file=src%2Fapp%2Fapp.module.ts.

    Why does the animation module break select dropdowns like this? I started having this issue after adding an Angular Material component to my app, which depends on the animations module.

    There are multiple Stack Overflow questions stemming from this bug:

  9. theodorejb commented on Nov 10, 2019

    @theodorejb
    Contributor

    Using my StackBlitz example, I opened the Firefox dev tools and set a breakpoint on DOM mutation of the select element subtree, as well as a breakpoint in the select_control_value_accessor writeValue method. Normally, the code to remove the submitted option element from the DOM runs before the writeValue method. However, when BrowserAnimationsModule is present, the order is reversed, and the submitted option element isn't removed until after writeValue is called. This makes the writeValue call pointless, as subsequent modification of the option elements overrides the select element value.

    Is there a bug in BrowserAnimationsModule that causes the order of operations to change, or does it change the order intentionally? It certainly seems like a bug for the module to change behavior like that even when no animations are being used.

  10. theodorejb commented on Nov 12, 2019

    @theodorejb
    Contributor

    This is still an problem in the latest Angular 9 release candidate with Ivy enabled. Fortunately I found that my patch in pull request #23784 will fix this issue if it is merged.

  11. xonuzofa commented on Apr 28, 2020

    @xonuzofa

    Also here: Issue 35896

  12. added
    P4
    on Oct 1, 2020
  13. 2 remaining items

  14. kheos31 commented on Feb 16, 2024

    @kheos31

    Hello everyone. As everybody, i'm sad to detect this issue again. Any news on the linked PR? We're currently faced to this problem and it's really annoying to have to try to predict in our externalized Angular libraries if an integration application will import BrowserAnimationModule or not..

  15. tobias74 commented on Dec 7, 2024

    @tobias74
    Author

    I have made a new Plunker for this: https://plnkr.co/edit/jI9GEvgQSTWNSTrf

    Here is how you can trigger the issue: Just click on "Click Me". After clicking the button the dropdown will show the first item as being selected (even when explicitly setting the value to an empty string). This behaviour only exists as long as the BrowserAnimationsModule is imported.

    In this Pluncker without the imported BrowserAnimationsModule everything works as expected: https://plnkr.co/edit/dLtdUfkgxm4iArx4

  16. angular-automatic-lock-bot commented on Jul 11, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  17. locked and limited conversation to collaborators on Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area: animationsfreq1: lowtype: bug/fix

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions