-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix(T34716): add an update method in the tooltip directory #542
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
61ebdbf
Fix(T34716): add update method to the tooltip directory
sakutademos e03320b
Fix(T34716): remove the value from the createTooltip method, as it is…
sakutademos df2bfca
Fix(T34716): Replace the old tooltip value with a new one by deleting…
sakutademos 4d1bc2a
Fix(T34716): add a comment
sakutademos 046c3cb
Fix(T34716): add options to the Tooltip update hook
sakutademos dc15c03
Fix(T34716): remove tooltip by id from the tooltips array when the de…
sakutademos f410255
Fix(T34716): refactored tooltip.js, save tooltips as an object
sakutademos 5b06b77
Fix(T34716): update changelog
sakutademos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,9 +5,11 @@ import { v4 as uuid } from 'uuid' | |||||
let handleShowTooltip = null | ||||||
let handleHideTooltip = null | ||||||
let handleTimeoutForDestroy = null | ||||||
let tooltips = [] | ||||||
|
||||||
const deleteTooltip = (tooltipEl) => { | ||||||
if (tooltipEl) { | ||||||
tooltips.filter(el => el.id !== tooltipEl.id) | ||||||
tooltipEl.remove() | ||||||
} | ||||||
} | ||||||
|
@@ -32,22 +34,24 @@ 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) => { | ||||||
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 = | ||||||
`<div class="tooltip absolute ${classes} z-below-zero" role="tooltip" id="${id}">` + | ||||||
`<div class="tooltip absolute ${classes} z-below-zero" role="tooltip" id="${tooltip.id}">` + | ||||||
`<div class="tooltip__arrow" data-tooltip-arrow></div>` + | ||||||
`<div class="tooltip__inner">${value}</div>` + | ||||||
`<div class="tooltip__inner">${tooltip.value}</div>` + | ||||||
`</div>` | ||||||
|
||||||
const range = document.createRange() | ||||||
el.setAttribute('aria-describedby', id) | ||||||
|
||||||
const content = range.createContextualFragment(tooltipHtml) | ||||||
|
||||||
|
@@ -59,11 +63,14 @@ const initTooltip = (el, value, options) => { | |||||
|
||||||
const id = `tooltip-${uuid()}` | ||||||
const zIndex = getZIndex(el) | ||||||
const tooltipData = { id: id, value: value } | ||||||
|
||||||
tooltips.push(tooltipData) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do You use an array and not an Object?
Suggested change
with that you can avoid the loop in line 145 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactored it here f410255. Use an object instead of an array |
||||||
el.setAttribute('aria-describedby', id) | ||||||
|
||||||
handleShowTooltip = () => showTooltip( | ||||||
id, | ||||||
el, | ||||||
value, | ||||||
options, | ||||||
zIndex | ||||||
) | ||||||
|
@@ -75,9 +82,9 @@ const initTooltip = (el, value, options) => { | |||||
el.addEventListener('blur', handleHideTooltip) | ||||||
} | ||||||
|
||||||
const showTooltip = async (id, wrapperEl, value, { place = 'top', container = 'body', classes = '' }, zIndex) => { | ||||||
const showTooltip = async (id, wrapperEl, { place = 'top', container = 'body', classes = '' }, zIndex) => { | ||||||
if (!document.getElementById(wrapperEl.getAttribute('aria-describedby'))) { | ||||||
createTooltip(id, wrapperEl, value, container, classes) | ||||||
createTooltip(id, container, classes) | ||||||
} else { | ||||||
clearTimeout(handleTimeoutForDestroy) | ||||||
} | ||||||
|
@@ -129,4 +136,24 @@ const showTooltip = async (id, wrapperEl, value, { place = 'top', container = 'b | |||||
tooltipEl.classList.remove('opacity-0') | ||||||
} | ||||||
|
||||||
export { destroyTooltip, initTooltip } | ||||||
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what for this is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored it f410255