1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00

Fix event handler removal on disconnect (#540)

* Fix event handler removal on disconnect

* Fix tab controller
This commit is contained in:
Jakub Kottnauer 2024-03-11 22:42:18 +01:00 committed by GitHub
parent c60ddaec1d
commit 2c3752668a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 19 additions and 25 deletions

View file

@ -8,24 +8,22 @@ export default class extends Controller {
connect() {
this.updateClasses(this.defaultTabValue);
document.addEventListener(
"turbo:load",
this.updateClasses.bind(this, this.defaultTabValue)
);
document.addEventListener("turbo:load", this.onTurboLoad);
}
disconnect() {
document.removeEventListener(
"turbo:load",
this.updateClasses.bind(this, this.defaultTabValue)
);
document.removeEventListener("turbo:load", this.onTurboLoad);
}
select(event) {
this.updateClasses(event.target.dataset.id);
}
updateClasses(selectedId) {
onTurboLoad = () => {
this.updateClasses(this.defaultTabValue);
}
updateClasses = (selectedId) => {
this.btnTargets.forEach((btn) => btn.classList.remove(this.activeClass));
this.tabTargets.forEach((tab) => tab.classList.add("hidden"));