Skip to content

Commit f9bd5d4

Browse files
crisbetoandrewseguin
authored andcommitted
fix(expansion-panel): animation not working in Angular 4.3 (#6442)
Fixes the animation not working correctly in Angular 4.3. It seems like having both the margin and height animation on the element causes the height one to break. This approach also has the advantage of making it easier to override the margin and being able to use the SASS variables if necessary.
1 parent 18c6dec commit f9bd5d4

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/lib/expansion/expansion-panel.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
@include mat-elevation-transition;
66
box-sizing: content-box;
77
display: block;
8+
margin: 0;
9+
transition: margin 225ms $mat-fast-out-slow-in-timing-function;
810

911
&:not([class*='mat-elevation-z']) {
1012
@include mat-elevation(2);
@@ -19,6 +21,10 @@
1921
padding: 0 24px 16px;
2022
}
2123

24+
.mat-expansion-panel-spacing {
25+
margin: 16px 0;
26+
}
27+
2228
.mat-action-row {
2329
border-top-style: solid;
2430
border-top-width: 1px;

src/lib/expansion/expansion-panel.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
transition,
2828
animate,
2929
} from '@angular/animations';
30-
import {MdAccordion, MdAccordionDisplayMode} from './accordion';
30+
import {MdAccordion} from './accordion';
3131
import {AccordionItem} from './accordion-item';
3232
import {UniqueSelectionDispatcher} from '../core';
3333
import {Subject} from 'rxjs/Subject';
@@ -57,7 +57,7 @@ export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,
5757
host: {
5858
'class': 'mat-expansion-panel',
5959
'[class.mat-expanded]': 'expanded',
60-
'[@displayMode]': '_getDisplayMode()',
60+
'[class.mat-expansion-panel-spacing]': '_hasSpacing()',
6161
},
6262
providers: [
6363
{provide: AccordionItem, useExisting: forwardRef(() => MdExpansionPanel)}
@@ -68,12 +68,6 @@ export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,
6868
state('expanded', style({height: '*', visibility: 'visible'})),
6969
transition('expanded <=> collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
7070
]),
71-
trigger('displayMode', [
72-
state('flat, collapsed', style({margin: '0'})),
73-
state('default', style({margin: '16px 0'})),
74-
transition('flat <=> collapsed, default <=> collapsed, flat <=> default',
75-
animate(EXPANSION_PANEL_ANIMATION_TIMING)),
76-
]),
7771
],
7872
})
7973
export class MdExpansionPanel extends AccordionItem implements OnChanges, OnDestroy {
@@ -98,13 +92,13 @@ export class MdExpansionPanel extends AccordionItem implements OnChanges, OnDest
9892
return this.hideToggle;
9993
}
10094

101-
/** Gets the panel's display mode. */
102-
_getDisplayMode(): MdAccordionDisplayMode | MdExpansionPanelState | 'void' {
95+
/** Determines whether the expansion panel should have spacing between it and its siblings. */
96+
_hasSpacing(): boolean {
10397
if (this.accordion) {
104-
return this.expanded ? this.accordion.displayMode : this._getExpandedState();
98+
return (this.expanded ? this.accordion.displayMode : this._getExpandedState()) === 'default';
10599
}
106100

107-
return 'void';
101+
return false;
108102
}
109103

110104
/** Gets the expanded state string. */

src/lib/expansion/expansion.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('MdExpansionPanel', () => {
8585
let panel = fixture.debugElement.query(By.css('md-expansion-panel'));
8686
let styles = getComputedStyle(panel.nativeElement);
8787

88-
expect(panel.componentInstance._getDisplayMode()).toBe('void');
88+
expect(panel.componentInstance._hasSpacing()).toBe(false);
8989
expect(styles.marginTop).toBe('13px');
9090
expect(styles.marginBottom).toBe('13px');
9191
expect(styles.marginLeft).toBe('37px');
@@ -97,7 +97,7 @@ describe('MdExpansionPanel', () => {
9797

9898
styles = getComputedStyle(panel.nativeElement);
9999

100-
expect(panel.componentInstance._getDisplayMode()).toBe('void');
100+
expect(panel.componentInstance._hasSpacing()).toBe(false);
101101
expect(styles.marginTop).toBe('13px');
102102
expect(styles.marginBottom).toBe('13px');
103103
expect(styles.marginLeft).toBe('37px');

0 commit comments

Comments
 (0)