Ronald 9d21736e9f
Add UI copyright headers files (#16614)
* Add copyright headers to UI files

* Ensure copywrite file ignores external libs
2023-03-14 09:18:55 -04:00

30 lines
918 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { modifier } from 'ember-modifier';
export default modifier(function enabled($element, [bool = true], hash) {
if (['input', 'textarea', 'select', 'button'].includes($element.nodeName.toLowerCase())) {
if (bool) {
$element.setAttribute('disabled', bool);
$element.setAttribute('aria-disabled', bool);
} else {
$element.dataset.disabled = false;
$element.removeAttribute('disabled');
$element.removeAttribute('aria-disabled');
}
return;
}
for (const $el of $element.querySelectorAll('input,textarea,button')) {
if (bool && $el.dataset.disabled !== 'false') {
$element.setAttribute('disabled', bool);
$element.setAttribute('aria-disabled', bool);
} else {
$element.removeAttribute('disabled');
$element.removeAttribute('aria-disabled');
}
}
});