Skip to content

Commit f58840c

Browse files
crisbetoandrewseguin
authored andcommitted
fix(expansion-panel): header animating on init when using non-default height (#16122)
Works around the expansion panel header animating on init, if its header is different from the default one. The original issue comes from the code introduced in #13088, but we can't remove that code, because it's there to work around a bug in Angular. Fixes #16067.
1 parent b7aa763 commit f58840c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ import {
5858
'[class.mat-expanded]': '_isExpanded()',
5959
'(click)': '_toggle()',
6060
'(keydown)': '_keydown($event)',
61+
'[@.disabled]': '_animationsDisabled',
62+
'(@expansionHeight.start)': '_animationStarted()',
6163
'[@expansionHeight]': `{
6264
value: _getExpandedState(),
6365
params: {
@@ -70,6 +72,9 @@ import {
7072
export class MatExpansionPanelHeader implements OnDestroy, FocusableOption {
7173
private _parentChangeSubscription = Subscription.EMPTY;
7274

75+
/** Whether Angular animations in the panel header should be disabled. */
76+
_animationsDisabled = true;
77+
7378
constructor(
7479
@Host() public panel: MatExpansionPanel,
7580
private _element: ElementRef,
@@ -108,6 +113,18 @@ export class MatExpansionPanelHeader implements OnDestroy, FocusableOption {
108113
}
109114
}
110115

116+
_animationStarted() {
117+
// Currently the `expansionHeight` animation has a `void => collapsed` transition which is
118+
// there to work around a bug in Angular (see #13088), however this introduces a different
119+
// issue. The new transition will cause the header to animate in on init (see #16067), if the
120+
// consumer has set a header height that is different from the default one. We work around it
121+
// by disabling animations on the header and re-enabling them after the first animation has run.
122+
// Note that Angular dispatches animation events even if animations are disabled. Ideally this
123+
// wouldn't be necessary if we remove the `void => collapsed` transition, but we have to wait
124+
// for https://github.com/angular/angular/issues/18847 to be resolved.
125+
this._animationsDisabled = false;
126+
}
127+
111128
/** Height of the header while the panel is expanded. */
112129
@Input() expandedHeight: string;
113130

tools/public_api_guard/material/expansion.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ export declare class MatExpansionPanelDescription {
7070
}
7171

7272
export declare class MatExpansionPanelHeader implements OnDestroy, FocusableOption {
73+
_animationsDisabled: boolean;
7374
collapsedHeight: string;
7475
readonly disabled: any;
7576
expandedHeight: string;
7677
panel: MatExpansionPanel;
7778
constructor(panel: MatExpansionPanel, _element: ElementRef, _focusMonitor: FocusMonitor, _changeDetectorRef: ChangeDetectorRef, defaultOptions?: MatExpansionPanelDefaultOptions);
79+
_animationStarted(): void;
7880
_getExpandedState(): string;
7981
_getPanelId(): string;
8082
_isExpanded(): boolean;

0 commit comments

Comments
 (0)