Skip to content

Commit 67d654c

Browse files
committed
fix rtl bugs
1 parent 1bbb27f commit 67d654c

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

Diff for: src/cdk/stepper/public_api.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import {CdkStepper, CdkStep} from './stepper';
1111
import {CommonModule} from '@angular/common';
1212
import {CdkStepLabel} from './step-label';
1313
import {CdkStepperNext, CdkStepperPrevious} from './stepper-button';
14+
import {BidiModule} from '@angular/cdk/bidi';
1415

1516
@NgModule({
16-
imports: [CommonModule],
17+
imports: [BidiModule, CommonModule],
1718
exports: [CdkStep, CdkStepper, CdkStepLabel, CdkStepperNext, CdkStepperPrevious],
1819
declarations: [CdkStep, CdkStepper, CdkStepLabel, CdkStepperNext, CdkStepperPrevious]
1920
})

Diff for: src/cdk/stepper/stepper.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import {
2121
ContentChild,
2222
ViewChild,
2323
TemplateRef,
24-
ViewEncapsulation
24+
ViewEncapsulation, Optional
2525
} from '@angular/core';
2626
import {LEFT_ARROW, RIGHT_ARROW, ENTER, SPACE} from '@angular/cdk/keycodes';
2727
import {CdkStepLabel} from './step-label';
2828
import {coerceBooleanProperty} from '@angular/cdk/coercion';
2929
import {AbstractControl} from '@angular/forms';
30+
import {Directionality} from '@angular/cdk/bidi';
3031

3132
/** Used to generate unique ID for each stepper component. */
3233
let nextId = 0;
@@ -164,7 +165,7 @@ export class CdkStepper {
164165
/** Used to track unique ID for each stepper component. */
165166
_groupId: number;
166167

167-
constructor() {
168+
constructor(@Optional() private _dir: Directionality) {
168169
this._groupId = nextId++;
169170
}
170171

@@ -224,10 +225,18 @@ export class CdkStepper {
224225
_onKeydown(event: KeyboardEvent) {
225226
switch (event.keyCode) {
226227
case RIGHT_ARROW:
227-
this._focusStep((this._focusIndex + 1) % this._steps.length);
228+
if (this._dir && this._dir.value === 'rtl') {
229+
this._focusStep((this._focusIndex + this._steps.length - 1) % this._steps.length);
230+
} else {
231+
this._focusStep((this._focusIndex + 1) % this._steps.length);
232+
}
228233
break;
229234
case LEFT_ARROW:
230-
this._focusStep((this._focusIndex + this._steps.length - 1) % this._steps.length);
235+
if (this._dir && this._dir.value === 'rtl') {
236+
this._focusStep((this._focusIndex + 1) % this._steps.length);
237+
} else {
238+
this._focusStep((this._focusIndex + this._steps.length - 1) % this._steps.length);
239+
}
231240
break;
232241
case SPACE:
233242
case ENTER:

Diff for: src/lib/stepper/stepper.scss

+20
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ $mat-stepper-line-gap: 8px !default;
4343
.mat-step-icon-not-touched {
4444
margin-right: $mat-stepper-line-gap;
4545
flex: none;
46+
47+
[dir="rtl"] & {
48+
margin-right: 0;
49+
margin-left: $mat-stepper-line-gap;
50+
}
4651
}
4752
}
4853

@@ -55,6 +60,11 @@ $mat-stepper-line-gap: 8px !default;
5560
.mat-step-icon,
5661
.mat-step-icon-not-touched {
5762
margin-right: $mat-vertical-stepper-content-margin - $mat-stepper-side-gap;
63+
64+
[dir="rtl"] & {
65+
margin-right: 0;
66+
margin-left: $mat-vertical-stepper-content-margin - $mat-stepper-side-gap;
67+
}
5868
}
5969
}
6070

@@ -75,6 +85,11 @@ $mat-stepper-line-gap: 8px !default;
7585
margin-left: $mat-vertical-stepper-content-margin;
7686
border: 0;
7787
position: relative;
88+
89+
[dir="rtl"] & {
90+
margin-left: 0;
91+
margin-right: $mat-vertical-stepper-content-margin;
92+
}
7893
}
7994

8095
.mat-stepper-vertical-line::before {
@@ -85,6 +100,11 @@ $mat-stepper-line-gap: 8px !default;
85100
left: 0;
86101
border-left-width: $mat-stepper-line-width;
87102
border-left-style: solid;
103+
104+
[dir="rtl"] & {
105+
left: auto;
106+
right: 0;
107+
}
88108
}
89109

90110
.mat-vertical-stepper-content {

0 commit comments

Comments
 (0)