Skip to content

Commit

Permalink
fix: multiple tippy renders (#3285)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob authored Sep 30, 2024
1 parent 9c91b75 commit 1f3f8cb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/javascript/avo.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ function initTippy() {
title = reference.getAttribute('tippy_title')
}

// Remove data-tippy to avoid multiples tippy renders for the same element
// Tag element with has-data-tippy
// Revert data-tippy attribute on turbo:before-cache to render the tippy on page navigation (ex when back button is pressed)
reference.removeAttribute('data-tippy')
reference.setAttribute('has-data-tippy', true)

return title
},
onShow(tooltipInstance) {
Expand Down Expand Up @@ -118,6 +124,10 @@ document.addEventListener('turbo:submit-start', () => document.body.classList.ad
document.addEventListener('turbo:submit-end', () => document.body.classList.remove('turbo-loading'))
document.addEventListener('turbo:before-cache', () => {
document.querySelectorAll('[data-turbo-remove-before-cache]').forEach((element) => element.remove())
document.querySelectorAll('[has-data-tippy="true"]').forEach((element) => {
element.removeAttribute('has-data-tippy')
element.setAttribute('data-tippy', 'tooltip')
})
})

window.Avo = window.Avo || { configuration: {} }
Expand Down

0 comments on commit 1f3f8cb

Please sign in to comment.