Skip to content

Commit d6d636c

Browse files
authored
Enable navigation bar reversal (#59)
- add a new input to the wizard and the navigation bar, which specifies the direction in which the steps should be layed out in the navigation bar - add documentation for the new navBarDirection input to the README file
1 parent 6f05a82 commit d6d636c

5 files changed

+47
-3
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ The first three layouts are showing circles with or without a background, for ea
8383
The second two layouts `large-filled-symbols` and `large-empty-symbols` optionally add a symbol in the center of the circle,
8484
for each step of your wizard, in the navigation bar, if such a symbol has been defined for the step.
8585

86+
#### \[navBarDirection\]
87+
Normally the steps in the navigation bar are layed out from left to right or from top to bottom.
88+
In some cases, like with languages that are written from right to left, it may be required to change this direction to layout the steps from right to left.
89+
To layout the steps from right to left you can pass `right-to-left` to the `navBarDirection` input of the wizard component.
90+
8691
#### \[navigationMode\]
8792
`ng2-archwizard` supports three different navigation modes:
8893
- **strict** navigation mode:
@@ -119,6 +124,7 @@ Possible `<wizard>` parameters:
119124
| ---------------------- | ----------------------------------------------------------------------------------------------------- | ------------- |
120125
| [navBarLocation] | `top` \| `bottom` \| `left` \| `right` | top |
121126
| [navBarLayout] | `small` \| `large-filled` \| `large-empty` \| `large-filled-symbols` \| `large-empty-symbols` | small |
127+
| [navBarDirection] | `left-to-right` \| `right-to-left` | left-to-right |
122128
| [navigationMode] | `strict` \| `semi-strict` \| `free` | strict |
123129
| [defaultStepIndex] | `number` | 0 |
124130
| [disableNavigationBar] | `boolean` | false |

src/components/wizard-navigation-bar.component.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,16 @@ describe('WizardNavigationBarComponent', () => {
521521
expect(navigationLinks[1].nativeElement.innerText).toBe('STEPTITLE 2');
522522
expect(navigationLinks[2].nativeElement.innerText).toBe('STEPTITLE 3');
523523
});
524+
525+
it('should show the correct reversed step titles', () => {
526+
wizardTest.wizard.navBarDirection = 'right-to-left';
527+
wizardTestFixture.detectChanges();
528+
529+
let navigationLinks = wizardTestFixture.debugElement.queryAll(By.css('wizard-navigation-bar ul li a'));
530+
531+
expect(navigationLinks.length).toBe(3);
532+
expect(navigationLinks[0].nativeElement.innerText).toBe('STEPTITLE 3');
533+
expect(navigationLinks[1].nativeElement.innerText).toBe('STEPTITLE 2');
534+
expect(navigationLinks[2].nativeElement.innerText).toBe('STEPTITLE 1');
535+
});
524536
});

src/components/wizard-navigation-bar.component.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component} from '@angular/core';
1+
import {Component, Input} from '@angular/core';
22
import {WizardStep} from '../util/wizard-step.interface';
33
import {WizardState} from '../navigation/wizard-state.model';
44
import {NavigationMode} from '../navigation/navigation-mode.interface';
@@ -22,6 +22,13 @@ import {NavigationMode} from '../navigation/navigation-mode.interface';
2222
styleUrls: ['wizard-navigation-bar.component.horizontal.less', 'wizard-navigation-bar.component.vertical.less']
2323
})
2424
export class WizardNavigationBarComponent {
25+
/**
26+
* The direction in which the wizard steps should be shown in the navigation bar.
27+
* This value can be either `left-to-right` or `right-to-left`
28+
*/
29+
@Input()
30+
public direction = 'left-to-right';
31+
2532
/**
2633
* The navigation mode
2734
*
@@ -45,7 +52,13 @@ export class WizardNavigationBarComponent {
4552
* @returns {Array<WizardStep>} An array containing all [[WizardStep]]s
4653
*/
4754
get wizardSteps(): Array<WizardStep> {
48-
return this.wizardState.wizardSteps;
55+
switch (this.direction) {
56+
case 'right-to-left':
57+
return this.wizardState.wizardSteps.reverse();
58+
case 'left-to-right':
59+
default:
60+
return this.wizardState.wizardSteps;
61+
}
4962
}
5063

5164
/**

src/components/wizard.component.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<wizard-navigation-bar
2+
[direction]="navBarDirection"
23
*ngIf="navBarLocation == 'top' || navBarLocation == 'left'"
34
[ngClass]="{
45
vertical: navBarLocation == 'left',
@@ -20,6 +21,7 @@
2021
</div>
2122

2223
<wizard-navigation-bar
24+
[direction]="navBarDirection"
2325
*ngIf="navBarLocation == 'bottom' || navBarLocation == 'right'"
2426
[ngClass]="{
2527
vertical: navBarLocation == 'right',

src/components/wizard.component.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ export class WizardComponent implements AfterContentInit {
7070
public navBarLayout = 'small';
7171

7272
/**
73-
* The navigation mode used for transitioning between different steps
73+
* The direction in which the steps inside the navigation bar should be shown.
74+
* The direction can be either `left-to-right` or `right-to-left`
75+
*
76+
* @type {string}
77+
*/
78+
@Input()
79+
public navBarDirection = 'left-to-right';
80+
81+
/**
82+
* The navigation mode used for transitioning between different steps.
83+
* The navigation mode can be either `strict`, `semi-strict` or `free`
7484
*
7585
* @type {string}
7686
*/
@@ -126,6 +136,7 @@ export class WizardComponent implements AfterContentInit {
126136

127137
/**
128138
* Constructor
139+
* @param {WizardState} model The model for this wizard component
129140
*/
130141
constructor(public model: WizardState) {
131142
}

0 commit comments

Comments
 (0)