@megha-ui/react 1.3.49 → 1.3.51
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.
|
@@ -8,7 +8,7 @@ import Text from "../text";
|
|
|
8
8
|
import Button from "../button";
|
|
9
9
|
import { HiChevronDown } from "react-icons/hi";
|
|
10
10
|
import { FaChevronDown, FaChevronUp } from "react-icons/fa";
|
|
11
|
-
const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select...", isMultiple = false, isSelectAll = false, className, style, labelAlignment = "vertical", labelFontSize, labelFontWeight, labelMarginBottom, labelClass, asteriskColor, label, disabled = false, width, searchEnabled = true, dropdownListWidth, marginBottom, marginTop, marginRight, marginLeft, required, dropdownListBG, searchBorderColor = "#2377ba", maxDropdownHeight, border = "1px solid #dbdfe9", selectedCharLength = 0, menuFrom = "left", Tooltip, DropDownIcon, onMenuClose, onMenuOpen, isClear, ClearIcon, clearId, selectedDisplay, checkboxWrapper, isSort = true, onSelectChange, isLoading = false, onApplyChange, withTooltip = false, isCreatable = false, onCreate = () => { }, autoPosition =
|
|
11
|
+
const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select...", isMultiple = false, isSelectAll = false, className, style, labelAlignment = "vertical", labelFontSize, labelFontWeight, labelMarginBottom, labelClass, asteriskColor, label, disabled = false, width, searchEnabled = true, dropdownListWidth, marginBottom, marginTop, marginRight, marginLeft, required, dropdownListBG, searchBorderColor = "#2377ba", maxDropdownHeight, border = "1px solid #dbdfe9", selectedCharLength = 0, menuFrom = "left", Tooltip, DropDownIcon, onMenuClose, onMenuOpen, isClear, ClearIcon, clearId, selectedDisplay, checkboxWrapper, isSort = true, onSelectChange, isLoading = false, onApplyChange, withTooltip = false, isCreatable = false, onCreate = () => { }, autoPosition = true, compactDisplay = false, ultraCompactDisplay = false, isGrouping = false, isIcon = false, withValue = false, closeOnSelect = true, }) => {
|
|
12
12
|
var _a, _b;
|
|
13
13
|
const { density } = useDensity();
|
|
14
14
|
const [isOpen, setIsOpen] = useState(false);
|
|
@@ -46,15 +46,28 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
46
46
|
return null;
|
|
47
47
|
};
|
|
48
48
|
const calculateAutoPosition = () => {
|
|
49
|
+
var _a, _b;
|
|
49
50
|
if (!wrapperRef.current)
|
|
50
51
|
return;
|
|
51
52
|
const rect = wrapperRef.current.getBoundingClientRect();
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
53
|
+
const boundaryParent = getLayoutBoundaryParent(wrapperRef.current);
|
|
54
|
+
const containerRect = boundaryParent === null || boundaryParent === void 0 ? void 0 : boundaryParent.getBoundingClientRect();
|
|
55
|
+
const containerTop = (_a = containerRect === null || containerRect === void 0 ? void 0 : containerRect.top) !== null && _a !== void 0 ? _a : 0;
|
|
56
|
+
const containerBottom = (_b = containerRect === null || containerRect === void 0 ? void 0 : containerRect.bottom) !== null && _b !== void 0 ? _b : window.innerHeight;
|
|
57
|
+
const viewportPadding = 8;
|
|
58
|
+
const menuGap = 8;
|
|
59
|
+
const minUsefulHeight = 180;
|
|
60
|
+
const preferredMaxHeight = typeof maxDropdownHeight === "number"
|
|
55
61
|
? maxDropdownHeight
|
|
56
62
|
: parseInt(`${maxDropdownHeight}`, 10) || 200;
|
|
57
|
-
|
|
63
|
+
const rawSpaceBelow = containerBottom - rect.bottom - viewportPadding - menuGap;
|
|
64
|
+
const rawSpaceAbove = rect.top - containerTop - viewportPadding - menuGap;
|
|
65
|
+
const spaceBelow = Math.max(0, Math.floor(rawSpaceBelow));
|
|
66
|
+
const spaceAbove = Math.max(0, Math.floor(rawSpaceAbove));
|
|
67
|
+
const shouldOpenTop = spaceBelow < minUsefulHeight && spaceAbove > spaceBelow;
|
|
68
|
+
const available = shouldOpenTop ? spaceAbove : spaceBelow;
|
|
69
|
+
const resolvedMax = Math.min(available, preferredMaxHeight);
|
|
70
|
+
if (shouldOpenTop) {
|
|
58
71
|
setClickStyle({ left: 0, bottom: "100%" });
|
|
59
72
|
}
|
|
60
73
|
else {
|
package/package.json
CHANGED