bits-ui 2.16.0 → 2.16.1
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.
|
@@ -55,6 +55,21 @@ export function useFloating(options) {
|
|
|
55
55
|
placement: placementOption,
|
|
56
56
|
strategy: strategyOption,
|
|
57
57
|
}).then((position) => {
|
|
58
|
+
const referenceNode = reference.current;
|
|
59
|
+
const referenceHidden = isReferenceHidden(referenceNode);
|
|
60
|
+
if (referenceHidden) {
|
|
61
|
+
// keep last good coordinates when the anchor disappears to avoid
|
|
62
|
+
// a transient jump to viewport origin before close propagates.
|
|
63
|
+
middlewareData = {
|
|
64
|
+
...middlewareData,
|
|
65
|
+
hide: {
|
|
66
|
+
// oxlint-disable-next-line no-explicit-any
|
|
67
|
+
...middlewareData.hide,
|
|
68
|
+
referenceHidden: true,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
58
73
|
// ignore bad coordinates that cause jumping during close transitions
|
|
59
74
|
if (!openOption && x !== 0 && y !== 0) {
|
|
60
75
|
// if we had a good position and now getting coordinates near
|
|
@@ -156,3 +171,12 @@ export function useFloating(options) {
|
|
|
156
171
|
},
|
|
157
172
|
};
|
|
158
173
|
}
|
|
174
|
+
function isReferenceHidden(node) {
|
|
175
|
+
if (!(node instanceof Element))
|
|
176
|
+
return false;
|
|
177
|
+
if (!node.isConnected)
|
|
178
|
+
return true;
|
|
179
|
+
if (node instanceof HTMLElement && node.hidden)
|
|
180
|
+
return true;
|
|
181
|
+
return node.getClientRects().length === 0;
|
|
182
|
+
}
|