From 61ebdbf0d95e7dfb70231eac745f163e43846323 Mon Sep 17 00:00:00 2001 From: Natalija Sakuta Date: Thu, 21 Sep 2023 13:56:17 +0200 Subject: [PATCH 1/8] Fix(T34716): add update method to the tooltip directory --- src/components/DpTooltip/utils/tooltip.js | 32 ++++++++++++++++++----- src/directives/Tooltip/Tooltip.js | 13 ++++++++- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/components/DpTooltip/utils/tooltip.js b/src/components/DpTooltip/utils/tooltip.js index 1b05655e6..a42ac2a4e 100644 --- a/src/components/DpTooltip/utils/tooltip.js +++ b/src/components/DpTooltip/utils/tooltip.js @@ -5,6 +5,7 @@ import { v4 as uuid } from 'uuid' let handleShowTooltip = null let handleHideTooltip = null let handleTimeoutForDestroy = null +let tooltips = [] const deleteTooltip = (tooltipEl) => { if (tooltipEl) { @@ -32,18 +33,21 @@ const getZIndex = (element) => { } const hideTooltip = (tooltipEl) => { - tooltipEl.classList.add('z-below-zero') - tooltipEl.classList.add('opacity-0') + if (tooltipEl) { + tooltipEl.classList.add('z-below-zero') + tooltipEl.classList.add('opacity-0') + } handleTimeoutForDestroy = setTimeout(() => deleteTooltip(tooltipEl), 300) } const createTooltip = (id, el, value, container, classes) => { - // this has to be in sync with the Template in DpTooltip + const tooltip = tooltips.find(el => el.id === id) + const tooltipHtml = - `` const range = document.createRange() - el.setAttribute('aria-describedby', id) const content = range.createContextualFragment(tooltipHtml) @@ -84,7 +83,7 @@ const initTooltip = (el, value, options) => { const showTooltip = async (id, wrapperEl, { place = 'top', container = 'body', classes = '' }, zIndex) => { if (!document.getElementById(wrapperEl.getAttribute('aria-describedby'))) { - createTooltip(id, wrapperEl, container, classes) + createTooltip(id, container, classes) } else { clearTimeout(handleTimeoutForDestroy) } @@ -136,16 +135,24 @@ const showTooltip = async (id, wrapperEl, { place = 'top', container = 'body', c tooltipEl.classList.remove('opacity-0') } -const updateTooltip = (elWrapper, value) => { +const updateTooltip = (elWrapper, value, options) => { if (!value) return const wrapperId = elWrapper.getAttribute('aria-describedby') + const zIndex = getZIndex(elWrapper) tooltips.forEach(el => { if (wrapperId === el.id) { el.value = value } }) + + const tooltipEl = document.getElementById(wrapperId) + + if (tooltipEl) { + deleteTooltip(tooltipEl) + showTooltip(wrapperId, elWrapper, options, zIndex) + } } export { destroyTooltip, initTooltip, updateTooltip } From 4d1bc2a86fd4c543430221bb1fe8bb818501ccfb Mon Sep 17 00:00:00 2001 From: Natalija Sakuta Date: Thu, 21 Sep 2023 15:19:59 +0200 Subject: [PATCH 4/8] Fix(T34716): add a comment --- src/components/DpTooltip/utils/tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/DpTooltip/utils/tooltip.js b/src/components/DpTooltip/utils/tooltip.js index 48c46bbf2..72e0088c0 100644 --- a/src/components/DpTooltip/utils/tooltip.js +++ b/src/components/DpTooltip/utils/tooltip.js @@ -43,7 +43,7 @@ const hideTooltip = (tooltipEl) => { const createTooltip = (id, container, classes) => { const tooltip = tooltips.find(el => el.id === id) - + // this has to be in sync with the Template in DpTooltip const tooltipHtml = `