@megha-ui/react 1.2.785 → 1.2.786
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,26 @@ 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
|
+
parent = parent.parentElement;
|
|
47
|
+
}
|
|
48
|
+
return fallback;
|
|
49
|
+
};
|
|
30
50
|
const calculateAutoPosition = () => {
|
|
31
51
|
if (!wrapperRef.current)
|
|
32
52
|
return;
|
|
@@ -298,9 +318,10 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
298
318
|
};
|
|
299
319
|
const handleClick = (e) => {
|
|
300
320
|
const clearEle = document.getElementById(clearId || "");
|
|
301
|
-
const screen = document.body.clientHeight;
|
|
302
321
|
const rect = e.currentTarget.getBoundingClientRect();
|
|
303
|
-
|
|
322
|
+
const viewportSpace = document.body.clientHeight - rect.bottom;
|
|
323
|
+
const overflowSpace = getOverflowParentHeight(wrapperRef.current, viewportSpace);
|
|
324
|
+
setHeight(overflowSpace);
|
|
304
325
|
if (clearEle === e.target) {
|
|
305
326
|
e.preventDefault();
|
|
306
327
|
}
|
package/package.json
CHANGED