Skip to content

Commit 11e2239

Browse files
crisbetojelbourn
authored andcommitted
feat(expansion-panel): allow for the panel header height to be customized (#6643)
Uses the new Angular animations features, that allow for dynamic values to be passed to an animation, to let consumers customize the `md-expansion-panel-header` height. Fixes #5641.
1 parent 730e7ae commit 11e2239

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/demo-app/expansion/expansion-demo.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<h1>Single Expansion Panel</h1>
2+
23
<md-expansion-panel class="md-expansion-demo-width" #myPanel>
3-
<md-expansion-panel-header>
4+
<md-expansion-panel-header [expandedHeight]="expandedHeight" [collapsedHeight]="collapsedHeight">
45
<mat-panel-description>This is a panel description.</mat-panel-description>
56
<mat-panel-title>Panel Title</mat-panel-title>
67
</md-expansion-panel-header>
@@ -10,7 +11,17 @@ <h1>Single Expansion Panel</h1>
1011
<button md-button>SAVE</button>
1112
</md-action-row>
1213
</md-expansion-panel>
14+
1315
<br>
16+
<md-form-field>
17+
<input mdInput [(ngModel)]="collapsedHeight" placeholder="Collapsed height">
18+
</md-form-field>
19+
20+
<md-form-field>
21+
<input mdInput [(ngModel)]="expandedHeight" placeholder="Expanded height">
22+
</md-form-field>
23+
<br>
24+
1425
<h1>Accordion</h1>
1526
<div>
1627
<p>Accordion Options</p>

src/demo-app/expansion/expansion-demo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ export class ExpansionDemo {
1313
hideToggle = false;
1414
disabled = false;
1515
showPanel3 = true;
16+
expandedHeight: string;
17+
collapsedHeight: string;
1618
}

src/lib/expansion/expansion-panel-header.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
OnDestroy,
1717
Renderer2,
1818
ElementRef,
19+
Input,
1920
} from '@angular/core';
2021
import {
2122
trigger,
@@ -56,7 +57,13 @@ import {Subscription} from 'rxjs/Subscription';
5657
'[class.mat-expanded]': '_isExpanded()',
5758
'(click)': '_toggle()',
5859
'(keyup)': '_keyup($event)',
59-
'[@expansionHeight]': '_getExpandedState()',
60+
'[@expansionHeight]': `{
61+
value: _getExpandedState(),
62+
params: {
63+
collapsedHeight: collapsedHeight,
64+
expandedHeight: expandedHeight
65+
}
66+
}`,
6067
},
6168
animations: [
6269
trigger('indicatorRotate', [
@@ -65,8 +72,16 @@ import {Subscription} from 'rxjs/Subscription';
6572
transition('expanded <=> collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
6673
]),
6774
trigger('expansionHeight', [
68-
state('collapsed', style({height: '48px'})),
69-
state('expanded', style({height: '64px'})),
75+
state('collapsed', style({
76+
height: '{{collapsedHeight}}',
77+
}), {
78+
params: {collapsedHeight: '48px'},
79+
}),
80+
state('expanded', style({
81+
height: '{{expandedHeight}}'
82+
}), {
83+
params: {expandedHeight: '64px'}
84+
}),
7085
transition('expanded <=> collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
7186
]),
7287
],
@@ -93,6 +108,12 @@ export class MdExpansionPanelHeader implements OnDestroy {
93108
_focusOriginMonitor.monitor(_element.nativeElement, _renderer, false);
94109
}
95110

111+
/** Height of the header while the panel is expanded. */
112+
@Input() expandedHeight: string;
113+
114+
/** Height of the header while the panel is collapsed. */
115+
@Input() collapsedHeight: string;
116+
96117
/** Toggles the expanded state of the panel. */
97118
_toggle(): void {
98119
if (!this.panel.disabled) {

0 commit comments

Comments
 (0)