@homecode/ui 5.20.14 → 5.20.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useRef, useEffect } from 'react';
|
|
3
3
|
import { TooltipCore } from './TooltipCore.js';
|
|
4
|
-
import {
|
|
4
|
+
import { applyTriggerTextStyles, getTextStyleSource, clearTriggerTextStyles } from './tooltipTextStyles.js';
|
|
5
5
|
|
|
6
|
+
function isPopoverOpen(el) {
|
|
7
|
+
try {
|
|
8
|
+
return el.matches(':popover-open');
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
6
14
|
const useSimplePositionSetup = ({ triggerRef, tooltipRef, content, delay, direction, }) => {
|
|
7
15
|
const timeoutRef = useRef();
|
|
8
16
|
useEffect(() => {
|
|
@@ -11,6 +19,10 @@ const useSimplePositionSetup = ({ triggerRef, tooltipRef, content, delay, direct
|
|
|
11
19
|
if (!trigger || !tooltip)
|
|
12
20
|
return;
|
|
13
21
|
const positionTooltip = () => {
|
|
22
|
+
// Measure from the corner: an old left near the viewport edge squeezes the
|
|
23
|
+
// width, wraps the text and makes the tooltip sit too high.
|
|
24
|
+
tooltip.style.left = '0px';
|
|
25
|
+
tooltip.style.top = '0px';
|
|
14
26
|
const rect = trigger.getBoundingClientRect();
|
|
15
27
|
const tooltipRect = tooltip.getBoundingClientRect();
|
|
16
28
|
let top = 0;
|
|
@@ -51,13 +63,19 @@ const useSimplePositionSetup = ({ triggerRef, tooltipRef, content, delay, direct
|
|
|
51
63
|
tooltip.hidePopover?.();
|
|
52
64
|
clearTriggerTextStyles(tooltip);
|
|
53
65
|
};
|
|
66
|
+
// New content while open: keep the trigger's font and re-center on the new size.
|
|
67
|
+
if (isPopoverOpen(tooltip)) {
|
|
68
|
+
applyTriggerTextStyles(tooltip, getTextStyleSource(trigger));
|
|
69
|
+
positionTooltip();
|
|
70
|
+
}
|
|
54
71
|
trigger.addEventListener('mouseenter', showTooltip);
|
|
55
72
|
trigger.addEventListener('mouseleave', hideTooltip);
|
|
56
73
|
trigger.addEventListener('focusin', showTooltip);
|
|
57
74
|
trigger.addEventListener('focusout', hideTooltip);
|
|
58
75
|
return () => {
|
|
59
76
|
clearTimeout(timeoutRef.current);
|
|
60
|
-
|
|
77
|
+
if (!isPopoverOpen(tooltip))
|
|
78
|
+
clearTriggerTextStyles(tooltip);
|
|
61
79
|
trigger.removeEventListener('mouseenter', showTooltip);
|
|
62
80
|
trigger.removeEventListener('mouseleave', hideTooltip);
|
|
63
81
|
trigger.removeEventListener('focusin', showTooltip);
|