diff --git a/packages/mermaid/src/dagre-wrapper/shapes/util.js b/packages/mermaid/src/dagre-wrapper/shapes/util.js index 1d0d2d77e6..7d1896c9a6 100644 --- a/packages/mermaid/src/dagre-wrapper/shapes/util.js +++ b/packages/mermaid/src/dagre-wrapper/shapes/util.js @@ -104,6 +104,7 @@ export const labelHelper = async (parent, node, _classes, isNode) => { bbox = div.getBoundingClientRect(); dv.attr('width', bbox.width); dv.attr('height', bbox.height); + dv.style('height', bbox.height + 'px'); } // Center the label diff --git a/packages/mermaid/src/rendering-util/createText.ts b/packages/mermaid/src/rendering-util/createText.ts index 462a4834f1..20625e7f4f 100644 --- a/packages/mermaid/src/rendering-util/createText.ts +++ b/packages/mermaid/src/rendering-util/createText.ts @@ -40,11 +40,14 @@ function addHtmlSpan(element, node, width, classes, addBackground = false) { div.style('display', 'table'); div.style('white-space', 'break-spaces'); div.style('width', width + 'px'); - bbox = div.node().getBoundingClientRect(); + const newBbox = div.node().getBoundingClientRect(); + if (newBbox.height > 0) { + bbox = newBbox; + } } - fo.style('width', bbox.width); - fo.style('height', bbox.height); + fo.style('width', bbox.width + 'px'); + fo.style('height', bbox.height + 'px'); return fo.node(); }