Skip to content

Commit

Permalink
Hide modal and background before turbo cache
Browse files Browse the repository at this point in the history
Fixes #203
  • Loading branch information
excid3 committed Mar 14, 2024
1 parent 0768c9e commit 9aa07f2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ export default class extends Controller {
restoreScroll: { type: Boolean, default: true }
}

connect() {
document.addEventListener("turbo:before-cache", this.beforeCache.bind(this))
}

disconnect() {
this.close()
document.removeEventListener("turbo:before-cache", this.beforeCache.bind(this))
}

open() {
Expand Down Expand Up @@ -78,4 +82,10 @@ export default class extends Controller {
if (this.scrollPosition === undefined) return
document.documentElement.scrollTop = this.scrollPosition
}

beforeCache() {
this.close()
this.backgroundTarget.classList.add("hidden")
this.containerTarget.classList.add("hidden")
}
}

0 comments on commit 9aa07f2

Please sign in to comment.