Skip to content

Commit

Permalink
fix(tooltip): add closing on click
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintonJason committed Oct 16, 2023
1 parent ad75aaf commit 844b25d
Show file tree
Hide file tree
Showing 2 changed files with 18,271 additions and 17,528 deletions.
10 changes: 8 additions & 2 deletions packages/sage-system/lib/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ Sage.tooltip = (function() {
// TODO: Reverting tooltip reveal on focus/blur until further investigation of persistent focus
// can resolve it lingering when it shouldn't.

function init(el) {
function init(el, onClick) {
el.addEventListener("mouseenter", buildToolTip);
// el.addEventListener("focus", buildToolTip);
el.addEventListener("mouseleave", removeTooltip);
el.addEventListener("click", function(ev) {
removeTooltip(ev);
if (onClick) {
onClick(ev);
}
});
// el.addEventListener("blur", removeTooltip);
}

Expand Down Expand Up @@ -50,7 +56,7 @@ Sage.tooltip = (function() {

// Removes tooltip from DOM
function removeTooltip(evt) {
if (!evt.target.hasAttribute(DATA_ATTR) || !document.querySelector(SELECTOR) || !evt.target.dataset.jsTooltip) return;
if (!evt.target.hasAttribute(DATA_ATTR) || !document.querySelector(SELECTOR) || !document.querySelector(`.${TOOLTIP_CLASS}`) || !evt.target.dataset.jsTooltip) return;

window.requestAnimationFrame(function() {
document.body.removeChild(document.querySelector(`.${TOOLTIP_CLASS}`));
Expand Down
Loading

0 comments on commit 844b25d

Please sign in to comment.