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
1 change: 1 addition & 0 deletions src/lib/stepper/stepper-horizontal.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<div *ngFor="let step of _steps; let i = index"
class="mat-horizontal-stepper-content" role="tabpanel"
[@stepTransition]="_getAnimationDirection(i)"
(@stepTransition.done)="_animationDone($event)"
[id]="_getStepContentId(i)"
[attr.aria-labelledby]="_getStepLabelId(i)"
[attr.aria-expanded]="selectedIndex === i">
Expand Down
1 change: 1 addition & 0 deletions src/lib/stepper/stepper-vertical.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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)"
[id]="_getStepContentId(i)"
[attr.aria-labelledby]="_getStepLabelId(i)"
[attr.aria-expanded]="selectedIndex === i">
Expand Down
24 changes: 23 additions & 1 deletion src/lib/stepper/stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import {StepperOrientation} from '@angular/cdk/stepper';
import {dispatchKeyboardEvent} from '@angular/cdk/testing';
import {Component, DebugElement} from '@angular/core';
import {async, ComponentFixture, inject, TestBed} from '@angular/core/testing';
import {async, ComponentFixture, inject, TestBed, fakeAsync, flush} from '@angular/core/testing';
import {
AbstractControl,
AsyncValidatorFn,
Expand Down Expand Up @@ -318,6 +318,28 @@ describe('MatStepper', () => {

expect(optionalLabel.textContent).toBe('Valgfri');
}));

it('should emit an event when the enter animation is done', fakeAsync(() => {
let stepper = fixture.debugElement.query(By.directive(MatStepper)).componentInstance;
let selectionChangeSpy = jasmine.createSpy('selectionChange spy');
let animationDoneSpy = jasmine.createSpy('animationDone spy');
let selectionChangeSubscription = stepper.selectionChange.subscribe(selectionChangeSpy);
let animationDoneSubscription = stepper.animationDone.subscribe(animationDoneSpy);

stepper.selectedIndex = 1;
fixture.detectChanges();

expect(selectionChangeSpy).toHaveBeenCalledTimes(1);
expect(animationDoneSpy).not.toHaveBeenCalled();

flush();

expect(selectionChangeSpy).toHaveBeenCalledTimes(1);
expect(animationDoneSpy).toHaveBeenCalledTimes(1);

selectionChangeSubscription.unsubscribe();
animationDoneSubscription.unsubscribe();
}));
});

describe('icon overrides', () => {
Expand Down
14 changes: 13 additions & 1 deletion src/lib/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

import {Directionality} from '@angular/cdk/bidi';
import {CdkStep, CdkStepper} from '@angular/cdk/stepper';
import {CdkStep, CdkStepper, StepContentPositionState} from '@angular/cdk/stepper';
import {AnimationEvent} from '@angular/animations';
import {
AfterContentInit,
ChangeDetectionStrategy,
Expand All @@ -16,9 +17,11 @@ import {
ContentChild,
ContentChildren,
Directive,
EventEmitter,
forwardRef,
Inject,
Optional,
Output,
QueryList,
SkipSelf,
TemplateRef,
Expand Down Expand Up @@ -82,6 +85,9 @@ export class MatStepper extends CdkStepper implements AfterContentInit {
/** Custom icon overrides passed in by the consumer. */
@ContentChildren(MatStepperIcon) _icons: QueryList<MatStepperIcon>;

/** Event emitted when the current step is done transitioning in. */
@Output() readonly animationDone: EventEmitter<void> = new EventEmitter<void>();

/** Consumer-specified template-refs to be used to override the header icons. */
_iconOverrides: {[key: string]: TemplateRef<MatStepperIconContext>} = {};

Expand All @@ -99,6 +105,12 @@ export class MatStepper extends CdkStepper implements AfterContentInit {
// 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();
}
}
}

@Component({
Expand Down