Skip to content

fix(expansion-panel): header animating on init when using non-default height #16122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/material/expansion/expansion-panel-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import {
'[class.mat-expanded]': '_isExpanded()',
'(click)': '_toggle()',
'(keydown)': '_keydown($event)',
'[@.disabled]': '_animationsDisabled',
'(@expansionHeight.start)': '_animationStarted()',
'[@expansionHeight]': `{
value: _getExpandedState(),
params: {
Expand All @@ -70,6 +72,9 @@ import {
export class MatExpansionPanelHeader implements OnDestroy, FocusableOption {
private _parentChangeSubscription = Subscription.EMPTY;

/** Whether Angular animations in the panel header should be disabled. */
_animationsDisabled = true;

constructor(
@Host() public panel: MatExpansionPanel,
private _element: ElementRef,
Expand Down Expand Up @@ -108,6 +113,18 @@ export class MatExpansionPanelHeader implements OnDestroy, FocusableOption {
}
}

_animationStarted() {
// Currently the `expansionHeight` animation has a `void => collapsed` transition which is
// there to work around a bug in Angular (see #13088), however this introduces a different
// issue. The new transition will cause the header to animate in on init (see #16067), if the
// consumer has set a header height that is different from the default one. We work around it
// by disabling animations on the header and re-enabling them after the first animation has run.
// Note that Angular dispatches animation events even if animations are disabled. Ideally this
// wouldn't be necessary if we remove the `void => collapsed` transition, but we have to wait
// for https://github.com/angular/angular/issues/18847 to be resolved.
this._animationsDisabled = false;
}

/** Height of the header while the panel is expanded. */
@Input() expandedHeight: string;

Expand Down
2 changes: 2 additions & 0 deletions tools/public_api_guard/material/expansion.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ export declare class MatExpansionPanelDescription {
}

export declare class MatExpansionPanelHeader implements OnDestroy, FocusableOption {
_animationsDisabled: boolean;
collapsedHeight: string;
readonly disabled: any;
expandedHeight: string;
panel: MatExpansionPanel;
constructor(panel: MatExpansionPanel, _element: ElementRef, _focusMonitor: FocusMonitor, _changeDetectorRef: ChangeDetectorRef, defaultOptions?: MatExpansionPanelDefaultOptions);
_animationStarted(): void;
_getExpandedState(): string;
_getPanelId(): string;
_isExpanded(): boolean;
Expand Down