Skip to content

Commit

Permalink
[JENKINS-71148] avoid empty tooltips (jenkinsci#8975)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
mawinter69 authored Feb 24, 2024
1 parent 6460778 commit 0675943
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions war/src/main/js/components/tooltips/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<br[ /]?\/?>|\\n/g, "\n"),
content: () => tooltip.replace(/<br[ /]?\/?>|\\n/g, "\n"),
onCreate(instance) {
instance.reference.setAttribute("title", instance.props.content);
},
Expand All @@ -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 =
Expand Down

0 comments on commit 0675943

Please sign in to comment.