Skip to content
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
2 changes: 1 addition & 1 deletion src/lib/stepper/stepper-horizontal.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@
<div *ngFor="let step of _steps; let i = index"
class="mat-horizontal-stepper-content" role="tabpanel"
[@stepTransition]="_getAnimationDirection(i)"
(@stepTransition.done)="_animationDone($event)"
(@stepTransition.done)="_animationDone.next($event)"
[id]="_getStepContentId(i)"
[attr.aria-labelledby]="_getStepLabelId(i)"
[attr.aria-expanded]="selectedIndex === i">
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stepper/stepper-vertical.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@
<div class="mat-vertical-content-container" [class.mat-stepper-vertical-line]="!isLast">
<div class="mat-vertical-stepper-content" role="tabpanel"
[@stepTransition]="_getAnimationDirection(i)"
(@stepTransition.done)="_animationDone($event)"
(@stepTransition.done)="_animationDone.next($event)"
[id]="_getStepContentId(i)"
[attr.aria-labelledby]="_getStepLabelId(i)"
[attr.aria-expanded]="selectedIndex === i">
Expand Down
25 changes: 17 additions & 8 deletions src/lib/stepper/stepper.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,8 @@ import {
import {FormControl, FormGroupDirective, NgForm} from '@angular/forms';
import {DOCUMENT} from '@angular/common';
import {ErrorStateMatcher} from '@angular/material/core';
import {takeUntil} from 'rxjs/operators';
import {Subject} from 'rxjs';
import {takeUntil, distinctUntilChanged} from 'rxjs/operators';

import {MatStepHeader} from './step-header';
import {MatStepLabel} from './step-label';
Expand DownExpand Up@@ -102,18 +103,26 @@ export class MatStepper extends _CdkStepper implements AfterContentInit {
/** Consumer-specified template-refs to be used to override the header icons. */
_iconOverrides: {[key: string]: TemplateRef<MatStepperIconContext>} = {};

/** Stream of animation `done` events when the body expands/collapses. */
_animationDone = new Subject<AnimationEvent>();

ngAfterContentInit() {
const icons = this._icons.toArray();
icons.forEach(({name, templateRef}) => this._iconOverrides[name] = templateRef);
this._icons.forEach(({name, templateRef}) => this._iconOverrides[name] = templateRef);

// Mark the component for change detection whenever the content children query changes
this._steps.changes.pipe(takeUntil(this._destroyed)).subscribe(() => this._stateChanged());
}

_animationDone(event: AnimationEvent) {
if ((event.toState as StepContentPositionState) === 'current') {
this.animationDone.emit();
}
this._animationDone.pipe(
// This needs a `distinctUntilChanged` in order to avoid emitting the same event twice due
// to a bug in animations where the `.done` callback gets invoked twice on some browsers.
// See https://github.com/angular/angular/issues/24084
distinctUntilChanged((x, y) => x.fromState === y.fromState && x.toState === y.toState),
takeUntil(this._destroyed)
).subscribe(event => {
if ((event.toState as StepContentPositionState) === 'current') {
this.animationDone.emit();
}
});
}
}

Expand Down