Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.
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
19 changes: 19 additions & 0 deletions packages/oui-stepper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@
</oui-stepper>
```

### Open Steps

```html:preview
<oui-stepper
current-index="$ctrl.currentStep">
<oui-step-form
header="Step1">
<p>Random content</p>
</oui-step-form>
<oui-step-form
header="Step2">
<oui-button variant="link" on-click="$ctrl.currentStep = 0">
<span>Go to Step 1</span>
</oui-button>
</oui-step-form>
</oui-stepper>
```

### Events on `oui-stepper`

**Note**: If you want to access the forms inside `on-finish` callback, you need to use the `forms` variable as below.
Expand Down Expand Up @@ -154,6 +172,7 @@
| ---- | ---- | ---- | ---- | ---- | ---- | ----
| `name` | string | @? | yes | n/a | n/a | stepper name used to identify step
| `id` | string | @? | yes | n/a | n/a | stepper id used to identify step
| `current-index` | number | =? | no | n/a | 0 | current step index
| `on-init` | function | & | no | n/a | n/a | initialization function
| `on-finish` | function | & | no | n/a | n/a | submit all steps function

Expand Down
27 changes: 27 additions & 0 deletions packages/oui-stepper/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,33 @@ describe("ouiStepper", () => {
expect(form2.hasClass(disabledClass)).toBe(false);
expect(form3.hasClass(disabledClass)).toBe(true);
});

it("should open designated step", () => {
const element = TestUtils.compileTemplate(`
<oui-stepper current-index="$ctrl.index">
<oui-step-form name="form1"></oui-step-form>
<oui-step-form name="form2"></oui-step-form>
<oui-step-form name="form3"></oui-step-form>
</oui-stepper>`, { index: 1 });

$timeout.flush();

const form1 = element.find("form").eq(0);
const form2 = element.find("form").eq(1);
const form3 = element.find("form").eq(2);

expect(form1.scope().$ctrl.stepper.focused).toBe(false);
expect(form2.scope().$ctrl.stepper.focused).toBe(true);
expect(form3.scope().$ctrl.stepper.focused).toBe(false);

element.scope().$ctrl.index = 2;

element.scope().$digest();

expect(form1.scope().$ctrl.stepper.focused).toBe(false);
expect(form2.scope().$ctrl.stepper.focused).toBe(false);
expect(form3.scope().$ctrl.stepper.focused).toBe(true);
});
});
});
});
3 changes: 2 additions & 1 deletion packages/oui-stepper/src/stepper.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export default {
name: "@",
id: "@",
onInit: "&",
onFinish: "&"
onFinish: "&",
currentIndex: "=?"
},
controller,
template,
Expand Down
12 changes: 10 additions & 2 deletions packages/oui-stepper/src/stepper.controller.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import get from "lodash/get";

export default class {
constructor ($attrs, $element, $timeout) {
constructor ($attrs, $element, $scope, $timeout) {
"ngInject";

this.$attrs = $attrs;
this.$element = $element;
this.$scope = $scope;
this.$timeout = $timeout;
}

$onInit () {
this.forms = [];
this.steps = [];
this.currentIndex = 0;
this.currentIndex = get(this, "currentIndex", 0);
this.onInit();
}

Expand All @@ -21,6 +24,11 @@ export default class {
.removeAttr("name")
.addClass("oui-stepper")
);

this.$scope.$watch(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid using $scope.$watch by using get/set of es6 :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to but I get RangeError: Maximum call stack size exceeded (I suppose due to the fact that currentIndex is needed to be set elsewhere)

() => this.currentIndex,
(index) => this.focusStep(index)
);
}

addStep (step) {
Expand Down