Merge pull request #1605 from joquitch/patch-1

fix(collapsible): moved binding to constructor
This commit is contained in:
gerjanvangeest 2022-02-16 14:13:14 +01:00 committed by GitHub
commit 3071695cd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/collapsible': patch
---
Moved binding to constructor to be be able to remove the event listener in disconnectedCallback

View file

@ -43,6 +43,7 @@ export class LionCollapsible extends LitElement {
constructor() {
super();
this.opened = false;
this.toggle = this.toggle.bind(this);
}
connectedCallback() {
@ -51,7 +52,7 @@ export class LionCollapsible extends LitElement {
const uid = uuid();
if (this._invokerNode) {
this._invokerNode.addEventListener('click', this.toggle.bind(this));
this._invokerNode.addEventListener('click', this.toggle);
this._invokerNode.setAttribute('aria-expanded', `${this.opened}`);
this._invokerNode.setAttribute('id', `collapsible-invoker-${uid}`);
this._invokerNode.setAttribute('aria-controls', `collapsible-content-${uid}`);