Skip to content

Commit a5c3387

Browse files
committed
privileged-action: use a fieldset instead of JS to disable children
1 parent 78c0f77 commit a5c3387

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

Diff for: app/components/privileged-action.hbs

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
{{yield to='placeholder'}}
99
</div>
1010
{{else}}
11-
<div local-class='placeholder' {{did-insert this.disableComponents}}>
12-
{{yield}}
11+
<div local-class='placeholder'>
12+
<fieldset disabled="disabled">
13+
{{yield}}
14+
</fieldset>
1315
<EmberTooltip>
1416
You must enable admin actions before you can perform this operation.
1517
</EmberTooltip>

Diff for: app/components/privileged-action.js

-10
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,4 @@ export default class PrivilegedAction extends Component {
4242
get canBePrivileged() {
4343
return !this.args.userAuthorised && this.session.currentUser?.is_admin && !this.session.isSudoEnabled;
4444
}
45-
46-
/**
47-
* @param {Element} element
48-
* @return {void}
49-
*/
50-
disableComponents(element) {
51-
[...element.querySelectorAll('input, select, textarea, button')].forEach(control => {
52-
control.setAttribute('disabled', 'disabled');
53-
});
54-
}
5545
}

Diff for: app/components/privileged-action.module.css

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
.placeholder {
2-
[disabled] {
2+
fieldset {
3+
border: 0;
4+
margin: 0;
5+
padding: 0;
6+
}
7+
8+
fieldset[disabled] {
39
cursor: not-allowed;
10+
11+
[disabled] {
12+
cursor: not-allowed;
13+
}
14+
15+
button,
16+
.yellow-button,
17+
.tan-button {
18+
/* This duplicates the styles in .button[disabled] as there's no
19+
* obvious way to compose them, given the target selectors. */
20+
background: linear-gradient(to bottom, var(--bg-color-top-light) 0%, var(--bg-color-bottom-light) 100%);
21+
color: var(--disabled-text-color);
22+
cursor: not-allowed;
23+
}
424
}
525
}

Diff for: tests/components/privileged-action-test.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,17 @@ module('Component | PrivilegedAction', hooks => {
111111
// We're trying to confirm that all the form controls are automatically
112112
// disabled.
113113
await render(hbs`
114-
<PrivilegedAction @userAuthorised={{false}}>
115-
<div data-test-content>
114+
<div data-test-content>
115+
<PrivilegedAction @userAuthorised={{false}}>
116116
<button data-test-control type="button">Click me maybe?</button>
117117
<label for="input">Input: </label><input data-test-control type="text" id="input" />
118118
<label for="select">Select: </label><select data-test-control id="select"><option>foo</option></select>
119119
<label for="textarea">Textarea: </label><textarea data-test-control id="textarea" />
120-
</div>
121-
</PrivilegedAction>
120+
</PrivilegedAction>
121+
</div>
122122
`);
123-
assert.dom('[data-test-content] [data-test-control]').exists().isDisabled();
123+
assert.dom('[data-test-content] fieldset').exists().isDisabled();
124+
assert.dom('[data-test-content] fieldset [data-test-control]').exists();
124125
});
125126

126127
test('automatic unprivileged block', async function (assert) {

0 commit comments

Comments
 (0)