Skip to content

Expansion panels in factoried content are open initially #16503

Closed

Description

@pburkindine

Factoried components containing expansion panels will show the expansion panels as open when the component is inside another (like sidenav) that enters the DOM. Non-factoried expansion panels do not have the same issue. Likely related to #11765

Reproduction

https://stackblitz.com/edit/sidenav-accordion-expansion

Steps to reproduce:

  1. Open the sidenav
  2. Should see the accordion is open during sidenav enter

Expected Behavior

Sidenav should not be open during sidenav enter

Environment

  • Angular: 8
  • CDK/Material: 8
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): OSX High Sierra

Activity

  1. benjaminkimble commented on Jul 18, 2019

    @benjaminkimble

    While it's still an issue I think needs to be fixed, I ran into this myself and have a workaround that may help other people out for now. If your situation allows, lazy loading (seen at bottom of docs page: https://material.angular.io/components/expansion/overview) and explicitly directing the panels to be closed with <mat-expansion-panel [expanded]="false">, they'll render closed, initially. At least they did for me. I still think it's a bug, but given how long it takes to fix things sometimes, it's probably better than waiting around if you need it.

  2. added
    P3
    on Jul 19, 2019
  3. lukasbuehler commented on Sep 7, 2019

    @lukasbuehler

    If your situation allows, lazy loading (seen at bottom of docs page: https://material.angular.io/components/expansion/overview) and explicitly directing the panels to be closed with <mat-expansion-panel [expanded]="false">, they'll render closed, initially.

    So the workaround worked for me when I surrounded the content of the expansion panel with:

    <ng-template matExpansionPanelContent>
        Your content
    </ng-template>

    You should end up with your panel looking something like this:

    <mat-expansion-panel>
        <mat-expansion-panel-header>
            This is the expansion title
        </mat-expansion-panel-header>
    
        <ng-template matExpansionPanelContent>
            Some deferred content
        </ng-template>
    </mat-expansion-panel>

    As suggested by @benjaminkimble and seen in the docs under as seen in https://material.angular.io/components/expansion/overview#lazy-rendering.

    A big improvement for me but it's not perfect because the padding-top or margin-top is changing now when it would show the content of the expansion panel before.

  4. self-assigned this
    on Dec 5, 2024
  5. added 2 commits that reference this issue on Dec 5, 2024
    bcfd6c3
    b35c757
  6. added 2 commits that reference this issue on Dec 5, 2024
    7b64c45
    aafa151
  7. angular-automatic-lock-bot commented on Jan 5, 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.

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

Metadata

Metadata

Assignees

Labels

P3area: material/expansion

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions