From f8e366455091a38ac25d297f70c112f0bdc602a4 Mon Sep 17 00:00:00 2001 From: Markus Winter Date: Sat, 24 Feb 2024 07:34:52 +0100 Subject: [PATCH] [JENKINS-71148] avoid empty tooltips (#8975) * [JENKINS71148] avoid empty tooltips when the tooltip or html tooltip is empty or whitespace only it is avoided that the tippy is invoked at all which would otherwise just display a small but empty element. * better null checks (cherry picked from commit 0675943cd256d383aa8a482371762f243d35d1a5) --- war/src/main/js/components/tooltips/index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/war/src/main/js/components/tooltips/index.js b/war/src/main/js/components/tooltips/index.js index 6b28e3e7f52b..eb74340f2180 100644 --- a/war/src/main/js/components/tooltips/index.js +++ b/war/src/main/js/components/tooltips/index.js @@ -19,16 +19,18 @@ function registerTooltip(element) { element._tippy.destroy(); } + const tooltip = element.getAttribute("tooltip"); + const htmlTooltip = element.getAttribute("data-html-tooltip"); if ( - element.hasAttribute("tooltip") && - !element.hasAttribute("data-html-tooltip") + tooltip !== null && + tooltip.trim().length > 0 && + (htmlTooltip === null || htmlTooltip.trim().length == 0) ) { tippy( element, Object.assign( { - content: (element) => - element.getAttribute("tooltip").replace(/|\\n/g, "\n"), + content: () => tooltip.replace(/|\\n/g, "\n"), onCreate(instance) { instance.reference.setAttribute("title", instance.props.content); }, @@ -44,12 +46,12 @@ function registerTooltip(element) { ); } - if (element.hasAttribute("data-html-tooltip")) { + if (htmlTooltip !== null && htmlTooltip.trim().length > 0) { tippy( element, Object.assign( { - content: (element) => element.getAttribute("data-html-tooltip"), + content: () => htmlTooltip, allowHTML: true, onCreate(instance) { instance.props.interactive =