Merge pull request #246 from ing-bank/chore/inputDatepickerCleanup

chore(input-datepicker): cleanup of old delegation mechanism
This commit is contained in:
Thijs Louisse 2019-08-14 15:49:55 +02:00 committed by GitHub
commit 84a422790f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@ import '@lion/calendar/lion-calendar.js';
import './lion-calendar-overlay-frame.js'; import './lion-calendar-overlay-frame.js';
/** /**
* @customElement * @customElement lion-input-datepicker
* @extends {LionInputDate} * @extends {LionInputDate}
*/ */
export class LionInputDatepicker extends LionInputDate { export class LionInputDatepicker extends LionInputDate {
@ -29,13 +29,6 @@ export class LionInputDatepicker extends LionInputDate {
type: String, type: String,
}, },
/**
* TODO: [delegation of disabled] move this to LionField (or FormControl) level
*/
disabled: {
type: Boolean,
},
__calendarMinDate: { __calendarMinDate: {
type: Date, type: Date,
}, },
@ -172,64 +165,22 @@ export class LionInputDatepicker extends LionInputDate {
.substr(2, 10)}`; .substr(2, 10)}`;
} }
/**
* Problem: we need to create a getter for disabled that puts disabled attrs on the invoker
* button.
* The DelegateMixin creates getters and setters regardless of what's defined on the prototype,
* thats why we need to move it out from parent delegations config, in order to make our own
* getters and setters work.
*
* TODO: [delegation of disabled] fix this on a global level:
* - LionField
* - move all delegations of attrs and props to static get props for docs
* - DelegateMixin needs to be refactored, so that it:
* - gets config from static get properties
* - hooks into _requestUpdate
*/
get delegations() {
return {
...super.delegations,
properties: super.delegations.properties.filter(p => p !== 'disabled'),
attributes: super.delegations.attributes.filter(p => p !== 'disabled'),
};
}
/**
* TODO: [delegation of disabled] move this to LionField (or FormControl) level
*/
_requestUpdate(name, oldValue) { _requestUpdate(name, oldValue) {
super._requestUpdate(name, oldValue); super._requestUpdate(name, oldValue);
if (name === 'disabled') {
this.__delegateDisabled();
}
if (name === 'disabled' || name === 'readOnly') { if (name === 'disabled' || name === 'readOnly') {
this.__toggleInvokerDisabled(); this.__toggleInvokerDisabled();
} }
} }
/**
* TODO: [delegation of disabled] move this to LionField (or FormControl) level
*/
__delegateDisabled() {
if (this.inputElement) {
this.inputElement.disabled = this.disabled;
}
}
__toggleInvokerDisabled() { __toggleInvokerDisabled() {
if (this._invokerElement) { if (this._invokerElement) {
this._invokerElement.disabled = this.disabled || this.readOnly; this._invokerElement.disabled = this.disabled || this.readOnly;
} }
} }
/**
* TODO: [delegation of disabled] move this to LionField (or FormControl) level
*/
firstUpdated(c) { firstUpdated(c) {
super.firstUpdated(c); super.firstUpdated(c);
this.__delegateDisabled();
this.__toggleInvokerDisabled(); this.__toggleInvokerDisabled();
} }