question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[mdExpansionPanel] margin animation (mat-expansion-panel-spacing) not triggered when used in custom component

See original GitHub issue

Bug, feature request, or proposal:

I would like to use the md-expansion-panel within a custom component e.g. bsm-current-item that has a md-expansion-panel, since it is best practice to make ‘dumb’ components.

But when you use a md-expansion-panel within a custom component, the mat-expansion-panel-spacing class is not triggered, since _hasSpacing() seems to be false. And the margin isn’t added.

bsm-current-item (dumb component)

# Simplied by using the example code
    <md-expansion-panel class="md-expansion-demo-width" #myPanel>
      <md-expansion-panel-header expandedHeight="104px" collapsedHeight="88px">
        <mat-panel-description>This is a panel description.</mat-panel-description>
        <mat-panel-title>Panel Title</mat-panel-title>
      </md-expansion-panel-header>
      This is the content text that makes sense here.
      <md-action-row>
        <button md-button (click)="myPanel.expanded = false">CANCEL</button>
        <button md-button>SAVE</button>
      </md-action-row>
    </md-expansion-panel>

bsm-playlist (host)

<md-accordion>
   <bsm-current-item *ngFor="let playlistItem of playlistItems$ | async | orderBy: 'orderNumber';" [playlistItem]="playlistItem">
</md-accordion>

Question

Wat is the proper way to handle this?

Not creating a custom component with the expansion panel behavior and adding the expansion panel code to bsm-playlist, works, but doesn’t seem/feels like a proper solution

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.3.2
node: 8.1.4
os: win32 x64
@angular/animations: 4.3.6
@angular/cdk: 2.0.0-beta.10-1b6b270
@angular/common: 4.3.6
@angular/compiler: 4.3.6
@angular/core: 4.3.6
@angular/flex-layout: 2.0.0-rc.1
@angular/forms: 4.3.6
@angular/http: 4.3.6
@angular/material: 2.0.0-beta.10-1b6b270
@angular/platform-browser: 4.3.6
@angular/platform-browser-dynamic: 4.3.6
@angular/platform-server: 4.3.6
@angular/router: 4.3.6
@angular/cli: 1.3.2
@angular/compiler-cli: 4.3.6
@angular/language-service: 4.3.6

Is there anything else we should know?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
willshowellcommented, Sep 8, 2017

@the-ult the tight coupling decision makes sense and IMO you should just make your smart/dumb split elsewhere. Try this:

<md-accordion>
  <md-expansion-panel *ngFor="item of items" [item]="item">

    <!-- Panel header -->
    <md-expansion-panel-header>
      <md-panel-title>
        <app-panel-title></app-panel-title>
      </md-panel-title>
      <md-panel-description>
        ...
      </md-panel-description>
    </md-expansion-panel-header>

    <!-- Panel content -->
    <app-player-stats [players]="players$ | async | orderBy: 'firstName'"></app-player-stats>

  </md-expansion-panel>
</md-accordion>

You may have to adjust your inputs/outputs appropriately (or use a common service to communicate with the dumb components), but you should be able to architect it just fine!

If you want to discuss app design decisions, maybe post on Stack Overflow or r/Angular2 and link back here. I’d be happy to chat more about it.

1reaction
josephperrottcommented, Sep 11, 2017

I’ll go ahead and close this issue since we have covered the tight coupling requirement for accordions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[mdExpansionPanel] margin animation (mat-expansion-panel ...
[mdExpansionPanel] margin animation (mat-expansion-panel-spacing) not triggered when used in custom component #6870.
Read more >
Expansion-panel from material angular 4 - Stack Overflow
It seems like you can now simply change the style in your components css file. So this should work: .mat-expansion-panel-body { padding: 0;...
Read more >
Expansion Panel | Angular Material
MatExpansionPanel extends CdkAccordionItem. This component can be used as a single element to show expandable content, or as one of multiple children of...
Read more >
demo/node_modules/@angular/material/@angular ... - GitLab
Use this to notify\n * components if the labels have changed after ... n * flat - no spacing is placed around expanded...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found