Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.

Commit e12bc46

Browse files
author
jleveugle
committed
feat(oui-stepper): add new attribute (editable)
By default, after validating a step, user can edit it and update his choice. <oui-step-form header="Simple step" description="This is a description"> we want to let our developpers decide when this update is possible. Today, user can do it as he wishes, this can be problematic in case of loading for example. Example: <oui-step-form header="Simple step" description="This is a description" editable="false"> will result by removing the link: "Modifying this step"
1 parent d7432ad commit e12bc46

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

packages/oui-stepper/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
| `loading-text` | string | @? | no | n/a | n/a | text for the loading state
172172
| `loading` | boolean | <? | no | `true`, `false` | `false` | display the loading state
173173
| `disabled` | boolean | <? | no | `true`, `false` | `false` | disable the step and shrink it
174+
| `editable` | boolean | <? | no | `true`, `false` | `true` | Define if user can go back on a step and edit it again
174175
| `navigation` | boolean | <? | no | `true`, `false` | `true` | show the navigation buttons
175176
| `skippable` | boolean | <? | no | `true`, `false` | `false` | add button to skip facultative step
176177
| `valid` | boolean | <? | no | `true`, `false` | `true` | custom validation for the form

packages/oui-stepper/src/index.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,52 @@ describe("ouiStepper", () => {
6262
expect(form.hasClass(completeClass)).toBe(false);
6363
});
6464

65+
it("should display a editable step", () => {
66+
let stepForm;
67+
const element = TestUtils.compileTemplate(`
68+
<oui-stepper>
69+
<oui-step-form name='form' on-submit="$ctrl.onSubmitTest(form)"></oui-step-form>
70+
</oui-stepper>`, {
71+
onSubmitTest: (form) => {
72+
stepForm = form;
73+
}
74+
});
75+
const form = element.find("form").eq(0);
76+
$timeout.flush();
77+
78+
form.triggerHandler("submit");
79+
80+
// $submitted is settled to false, fake it by access form directly and set it to true
81+
stepForm.$submitted = true;
82+
element.scope().$digest();
83+
84+
const editLink = angular.element(element[0].querySelector("button.oui-button.oui-button_link"));
85+
expect(editLink.length).toBe(1);
86+
});
87+
88+
it("should display a not-editable step", () => {
89+
let stepForm;
90+
const element = TestUtils.compileTemplate(`
91+
<oui-stepper>
92+
<oui-step-form name='form' on-submit="$ctrl.onSubmitTest(form)" editable="false"></oui-step-form>
93+
</oui-stepper>`, {
94+
onSubmitTest: (form) => {
95+
stepForm = form;
96+
}
97+
});
98+
const form = element.find("form").eq(0);
99+
$timeout.flush();
100+
101+
form.triggerHandler("submit");
102+
103+
// $submitted is settled to false, fake it by access form directly and set it to true
104+
stepForm.$submitted = true;
105+
element.scope().$digest();
106+
107+
const editLink = angular.element(element[0].querySelector("button.oui-button.oui-button_link"));
108+
expect(editLink.length).toBe(0);
109+
});
110+
65111
it("should display a loader", () => {
66112
const element = TestUtils.compileTemplate("<oui-stepper><oui-step-form loading></oui-step-form></oui-stepper>");
67113
$timeout.flush();

packages/oui-stepper/src/step-form/step-form.component.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default {
1717
submitText: "@?",
1818

1919
disabled: "<?",
20+
editable: "<?",
2021
loading: "<?",
2122
navigation: "<?",
2223
skippable: "<?",

packages/oui-stepper/src/step-form/step-form.controller.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class StepFormController {
1313

1414
$onInit () {
1515
addBooleanParameter(this, "disabled");
16+
addBooleanParameter(this, "editable");
1617
addBooleanParameter(this, "skippable");
1718

1819
// Add default name
@@ -23,6 +24,11 @@ export default class StepFormController {
2324
addDefaultParameter(this, "cancelText", this.translations.cancelButtonLabel);
2425
}
2526

27+
// By default, we can edit a step
28+
if (angular.isUndefined(this.$attrs.editable)) {
29+
this.editable = true;
30+
}
31+
2632
// Show validation if no attribute 'navigation'
2733
if (angular.isUndefined(this.$attrs.navigation)) {
2834
this.navigation = true;

packages/oui-stepper/src/step-form/step-form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ng-bind="::$ctrl.translations.optionalLabel">
1616
</span>
1717
<button class="oui-button oui-button_link" type="button"
18-
ng-if="!$ctrl.stepper.focused && !$ctrl.stepper.disabled && this[$ctrl.name].$submitted"
18+
ng-if="!$ctrl.stepper.focused && !$ctrl.stepper.disabled && $ctrl.editable && this[$ctrl.name].$submitted"
1919
ng-click="$ctrl.setFocus(this[$ctrl.name])"
2020
ng-bind="::$ctrl.translations.modifyThisStep"></button>
2121
</header>

0 commit comments

Comments
 (0)