Skip to content

Commit

Permalink
Adds a {{disabled}} modifier that works similar to fieldset
Browse files Browse the repository at this point in the history
In that you can set it to false on a parent node and all its sub nodes
will be disabled. It has an added improvement that you can then separate
allow children if you want to disable everything apart from one thing.

One caveat here is that it relies on dom twiddling and is therefore
disabling a parent is not currently very reactive and will need some
MutationObserver work to make it fully reactive.
  • Loading branch information
John Cowen committed Feb 4, 2021
1 parent 8ec39f0 commit f0cc8cb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ui/packages/consul-ui/app/modifiers/disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { modifier } from 'ember-modifier';

export default modifier(function enabled($element, [bool], hash) {
if (['input', 'textarea', 'select', 'button'].includes($element.nodeName.toLowerCase())) {
if (bool) {
$element.disabled = bool;
} else {
$element.dataset.disabled = false;
}
return;
}
for (const $el of $element.querySelectorAll('input,textarea')) {
if ($el.dataset.disabled !== 'false') {
$el.disabled = bool;
}
}
});

0 comments on commit f0cc8cb

Please sign in to comment.