@logo-elements/component-base
Version:
A set of mixins used by Logo Elements which is extended from Vaadin components.
67 lines (62 loc) • 1.7 kB
JavaScript
/**
* @license
* Copyright LOGO YAZILIM SANAYİ VE TİCARET A.Ş.
*
* Save to the extent permitted by law, you may not use, copy, modify,
* distribute or create derivative works of this material or any part
* of it without the prior written consent of LOGO YAZILIM SANAYİ VE TİCARET A.Ş. Limited.
* Any reproduction of this material must contain this notice.
*/
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
/**
* A mixin to provide disabled property for field components.
*
* @polymerMixin
*/
export const DisabledMixin = dedupingMixin(
(superclass) =>
class DisabledMixinClass extends superclass {
static get properties() {
return {
/**
* If true, the user cannot interact with this element.
*/
disabled: {
type: Boolean,
value: false,
observer: '_disabledChanged',
reflectToAttribute: true
}
};
}
/**
* @param {boolean} disabled
* @protected
*/
_disabledChanged(disabled) {
this._setAriaDisabled(disabled);
}
/**
* @param {boolean} disabled
* @protected
*/
_setAriaDisabled(disabled) {
if (disabled) {
this.setAttribute('aria-disabled', 'true');
} else {
this.removeAttribute('aria-disabled');
}
}
/**
* Overrides the default element `click` method in order to prevent
* firing the `click` event when the element is disabled.
* @protected
* @override
*/
click() {
if (!this.disabled) {
super.click();
}
}
}
);