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

Commit f763666

Browse files
euhmeuhAxelPeter
authored andcommitted
feat(oui-modal): allow disabling oui-modal buttons (#307)
* feat(oui-modal): allow disabling oui-modal buttons * feat(oui-modal): fix test and clean up the doc
1 parent ac77580 commit f763666

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

packages/oui-modal/README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@
4444
<div ng-init="$ctrl.loading = true" class="oui-doc-preview-only-keep-children">
4545
<oui-modal
4646
heading="Loading modal title"
47-
primary-action="$ctrl.confirm = true"
47+
primary-action="$ctrl.doSomething()"
4848
primary-label="Ok"
49-
secondary-action="$ctrl.cancel = true"
49+
secondary-action="$ctrl.cancel()"
5050
secondary-label="Cancel"
51-
on-dismiss="$ctrl.cancel = true"
5251
loading="$ctrl.loading">
5352
<oui-field label="Label for Input text">
5453
<input type="text" id="text" name="text" class="oui-input">
@@ -61,17 +60,29 @@
6160
### Warning modal
6261

6362
```html:preview
64-
<div ng-init="$ctrl.dismiss = false"
65-
class="oui-doc-preview-only-keep-children">
6663
<oui-modal
6764
heading="Warning modal"
68-
primary-action="$ctrl.dismiss = true"
65+
primary-action="$ctrl.doSomething()"
6966
primary-label="Ok"
70-
on-dismiss="$ctrl.dismiss = true"
67+
on-dismiss="$ctrl.dismiss()"
7168
type="warning">
7269
Modal content
7370
</oui-modal>
74-
</div>
71+
```
72+
73+
### Disabled buttons
74+
75+
```html:preview
76+
<oui-modal
77+
heading="Fight a wizard on a bridge"
78+
primary-action="$ctrl.pass()"
79+
primary-label="Pass"
80+
primary-disabled="true"
81+
secondary-action="$ctrl.flee()"
82+
secondary-label="Turn back"
83+
secondary-disabled="true">
84+
You shall not pass!
85+
</oui-modal>
7586
```
7687

7788
## API
@@ -83,8 +94,10 @@
8394
| `loading` | boolean | <? | no | `true`, `false` | `false` | display loader flag
8495
| `primary-label` | string | @? | yes | n/a | n/a | confirmation label
8596
| `primary-action` | function | & | no | n/a | n/a | confirmation callback
97+
| `primary-disabled` | boolean | <? | no | `true`, `false` | `false` | disable the primary button
8698
| `secondary-label` | string | @? | yes | n/a | n/a | cancellation label
8799
| `secondary-action` | function | & | no | n/a | n/a | cancellation callback
100+
| `secondary-disabled` | boolean | <? | no | `true`, `false` | `false` | disable the secondary button
88101
| `on-dismiss` | function | & | no | n/a | n/a | dismiss callback
89102

90103
#### Deprecated

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,35 @@ describe("ouiModal", () => {
177177
expect($secondaryButton.attr("disabled")).toBe("disabled");
178178
});
179179

180+
it("should disable buttons when the conditions are met", () => {
181+
const primaryDisabled = true;
182+
const secondaryDisabled = true;
183+
184+
const element = TestUtils.compileTemplate(`
185+
<oui-modal
186+
heading="Title"
187+
primary-label="{{::$ctrl.primaryLabel}}"
188+
primary-disabled="$ctrl.primaryDisabled"
189+
secondary-label="{{::$ctrl.secondaryLabel}}"
190+
secondary-disabled="$ctrl.secondaryDisabled">
191+
</oui-modal>
192+
`, {
193+
primaryLabel,
194+
secondaryLabel,
195+
primaryDisabled,
196+
secondaryDisabled
197+
});
198+
199+
const $footer = getFooter(element);
200+
const $primaryButton = getPrimaryButton($footer);
201+
const $secondaryButton = getSecondaryButton($footer);
202+
203+
expect($primaryButton).toBeDefined();
204+
expect($primaryButton.attr("disabled")).toBe("disabled");
205+
expect($secondaryButton).toBeDefined();
206+
expect($secondaryButton.attr("disabled")).toBe("disabled");
207+
});
208+
180209
it("should trigger secondary action", () => {
181210
const secondarySpy = jasmine.createSpy("secondaryClick");
182211
const element = TestUtils.compileTemplate(`

packages/oui-modal/src/modal.component.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export default {
1111
loading: "<?",
1212
primaryLabel: "@?",
1313
primaryAction: "&",
14+
primaryDisabled: "<?",
1415
secondaryLabel: "@?",
1516
secondaryAction: "&",
17+
secondaryDisabled: "<?",
1618
onDismiss: "&"
1719
},
1820
transclude: true

packages/oui-modal/src/modal.controller.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export default class {
1111

1212
$onInit () {
1313
addBooleanParameter(this, "loading");
14+
addBooleanParameter(this, "primaryDisabled");
15+
addBooleanParameter(this, "secondaryDisabled");
1416

1517
// Deprecated: Support for 'title' attribute
1618
if (!!this.$attrs.title && !this.$attrs.heading) {

packages/oui-modal/src/modal.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
ng-if="$ctrl.secondaryLabel"
2929
ng-bind="$ctrl.secondaryLabel"
3030
ng-click="$ctrl.secondaryAction()"
31-
ng-disabled="$ctrl.loading">
31+
ng-disabled="$ctrl.loading || $ctrl.secondaryDisabled">
3232
</button>
3333
<button class="oui-button oui-button_primary"
3434
type="submit"
3535
ng-if="$ctrl.primaryLabel"
3636
ng-bind="$ctrl.primaryLabel"
3737
ng-click="$ctrl.primaryAction()"
38-
ng-disabled="$ctrl.loading">
38+
ng-disabled="$ctrl.loading || $ctrl.primaryDisabled">
3939
</button>
4040
</div>

0 commit comments

Comments
 (0)