fix(switch): fix error caused by setting role in constructor (#1741)
Co-authored-by: jorenbroekema <joren.broekema@gmail.com> Co-authored-by: jorenbroekema <joren.broekema@gmail.com>
This commit is contained in:
parent
5be7776e1e
commit
718ce0146a
3 changed files with 15 additions and 1 deletions
5
.changeset/wise-carrots-mix.md
Normal file
5
.changeset/wise-carrots-mix.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/switch': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix switch to set role in connectedCallback instead of constructor (throws error).
|
||||||
|
|
@ -72,7 +72,6 @@ export class LionSwitch extends ScopedElementsMixin(ChoiceInputMixin(LionField))
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.role = 'switch';
|
|
||||||
this.checked = false;
|
this.checked = false;
|
||||||
/** @private */
|
/** @private */
|
||||||
this.__handleButtonSwitchCheckedChanged = this.__handleButtonSwitchCheckedChanged.bind(this);
|
this.__handleButtonSwitchCheckedChanged = this.__handleButtonSwitchCheckedChanged.bind(this);
|
||||||
|
|
@ -80,6 +79,9 @@ export class LionSwitch extends ScopedElementsMixin(ChoiceInputMixin(LionField))
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
if (!this.role) {
|
||||||
|
this.role = 'switch';
|
||||||
|
}
|
||||||
this.addEventListener('checked-changed', this.__handleButtonSwitchCheckedChanged);
|
this.addEventListener('checked-changed', this.__handleButtonSwitchCheckedChanged);
|
||||||
if (this._labelNode) {
|
if (this._labelNode) {
|
||||||
this._labelNode.addEventListener('click', this._toggleChecked);
|
this._labelNode.addEventListener('click', this._toggleChecked);
|
||||||
|
|
|
||||||
|
|
@ -213,4 +213,11 @@ describe('lion-switch', () => {
|
||||||
);
|
);
|
||||||
expect(el.showsFeedbackFor).to.eql(['info']);
|
expect(el.showsFeedbackFor).to.eql(['info']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not cause error by setting an attribute in the constructor', async () => {
|
||||||
|
const div = await fixture(html`<div></div>`);
|
||||||
|
const el = /** @type {LionSwitch} */ (document.createElement('lion-switch'));
|
||||||
|
div.appendChild(el);
|
||||||
|
expect(el.role).to.equal('switch');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue