@megha-ui/react 1.2.785 → 1.2.787
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.
|
@@ -27,6 +27,28 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
27
27
|
});
|
|
28
28
|
const [collapsed, setCollapsed] = useState("");
|
|
29
29
|
const [height, setHeight] = useState(0);
|
|
30
|
+
const getOverflowParentHeight = (element, fallback) => {
|
|
31
|
+
if (!element)
|
|
32
|
+
return fallback;
|
|
33
|
+
let parent = element.parentElement;
|
|
34
|
+
while (parent) {
|
|
35
|
+
const style = window.getComputedStyle(parent);
|
|
36
|
+
const overflowY = style.overflowY;
|
|
37
|
+
const overflow = style.overflow;
|
|
38
|
+
if (overflowY === "auto" ||
|
|
39
|
+
overflowY === "scroll" ||
|
|
40
|
+
overflow === "auto" ||
|
|
41
|
+
overflow === "scroll") {
|
|
42
|
+
const parentRect = parent.getBoundingClientRect();
|
|
43
|
+
const elementRect = element.getBoundingClientRect();
|
|
44
|
+
return parentRect.bottom - elementRect.bottom;
|
|
45
|
+
}
|
|
46
|
+
console.log({ parent });
|
|
47
|
+
parent = parent.parentElement;
|
|
48
|
+
console.log({ parent });
|
|
49
|
+
}
|
|
50
|
+
return fallback;
|
|
51
|
+
};
|
|
30
52
|
const calculateAutoPosition = () => {
|
|
31
53
|
if (!wrapperRef.current)
|
|
32
54
|
return;
|
|
@@ -298,9 +320,10 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
298
320
|
};
|
|
299
321
|
const handleClick = (e) => {
|
|
300
322
|
const clearEle = document.getElementById(clearId || "");
|
|
301
|
-
const screen = document.body.clientHeight;
|
|
302
323
|
const rect = e.currentTarget.getBoundingClientRect();
|
|
303
|
-
|
|
324
|
+
const viewportSpace = document.body.clientHeight - rect.bottom;
|
|
325
|
+
const overflowSpace = getOverflowParentHeight(wrapperRef.current, viewportSpace);
|
|
326
|
+
setHeight(overflowSpace);
|
|
304
327
|
if (clearEle === e.target) {
|
|
305
328
|
e.preventDefault();
|
|
306
329
|
}
|
package/package.json
CHANGED