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
8 changes: 6 additions & 2 deletions src/cdk/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
} from '@angular/core';
import {AbstractControl} from '@angular/forms';
import {CdkStepLabel} from './step-label';
import {Subject} from 'rxjs';
import {Observable, Subject, of as obaservableOf} from 'rxjs';
import {startWith, takeUntil} from 'rxjs/operators';

/** Used to generate unique ID for each stepper component. */
let nextId = 0;
Expand Down Expand Up @@ -212,9 +213,12 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
ngAfterViewInit() {
this._keyManager = new FocusKeyManager(this._stepHeader)
.withWrap()
.withHorizontalOrientation(this._layoutDirection())
.withVerticalOrientation(this._orientation === 'vertical');

(this._dir ? this._dir.change as Observable<Direction> : obaservableOf())
.pipe(startWith(this._layoutDirection()), takeUntil(this._destroyed))
.subscribe(direction => this._keyManager.withHorizontalOrientation(direction));

this._keyManager.updateActiveItemIndex(this._selectedIndex);
}

Expand Down
31 changes: 24 additions & 7 deletions src/lib/stepper/stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@angular/cdk/keycodes';
import {StepperOrientation} from '@angular/cdk/stepper';
import {dispatchKeyboardEvent} from '@angular/cdk/testing';
import {Component, DebugElement} from '@angular/core';
import {Component, DebugElement, EventEmitter} from '@angular/core';
import {async, ComponentFixture, inject, TestBed, fakeAsync, flush} from '@angular/core/testing';
import {
AbstractControl,
Expand All @@ -35,10 +35,13 @@ import {MatStepperIntl} from './stepper-intl';
const VALID_REGEX = /valid/;

describe('MatStepper', () => {
let dir: Direction;
let dir: {value: Direction, change: EventEmitter<Direction>};

beforeEach(async(() => {
dir = 'ltr';
dir = {
value: 'ltr',
change: new EventEmitter()
};

TestBed.configureTestingModule({
imports: [MatStepperModule, NoopAnimationsModule, ReactiveFormsModule],
Expand All @@ -53,7 +56,7 @@ describe('MatStepper', () => {
LinearStepperWithValidOptionalStep,
],
providers: [
{provide: Directionality, useFactory: () => ({value: dir})}
{provide: Directionality, useFactory: () => dir}
]
});

Expand Down Expand Up @@ -388,7 +391,7 @@ describe('MatStepper', () => {
let fixture: ComponentFixture<SimpleMatVerticalStepperApp>;

beforeEach(() => {
dir = 'rtl';
dir.value = 'rtl';
fixture = TestBed.createComponent(SimpleMatVerticalStepperApp);
fixture.detectChanges();
});
Expand Down Expand Up @@ -717,7 +720,7 @@ describe('MatStepper', () => {
});

it('should reverse arrow key focus in RTL mode', () => {
dir = 'rtl';
dir.value = 'rtl';
let fixture = TestBed.createComponent(SimpleMatVerticalStepperApp);
fixture.detectChanges();

Expand All @@ -744,13 +747,27 @@ describe('MatStepper', () => {
});

it('should reverse arrow key focus in RTL mode', () => {
dir = 'rtl';
dir.value = 'rtl';
let fixture = TestBed.createComponent(SimpleMatHorizontalStepperApp);
fixture.detectChanges();

let stepHeaders = fixture.debugElement.queryAll(By.css('.mat-horizontal-stepper-header'));
assertArrowKeyInteractionInRtl(fixture, stepHeaders);
});

it('should reverse arrow key focus when switching into RTL after init', () => {
let fixture = TestBed.createComponent(SimpleMatHorizontalStepperApp);
fixture.detectChanges();

let stepHeaders = fixture.debugElement.queryAll(By.css('.mat-horizontal-stepper-header'));
assertCorrectKeyboardInteraction(fixture, stepHeaders, 'horizontal');

dir.value = 'rtl';
dir.change.emit('rtl');
fixture.detectChanges();

assertArrowKeyInteractionInRtl(fixture, stepHeaders);
});
});

describe('valid step in linear stepper', () => {
Expand Down