fui-material 2.1.11 → 2.1.13
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.
package/dist/f-ui-kit.es.js
CHANGED
|
@@ -2977,14 +2977,45 @@ const FSelectSearchDb = ({
|
|
|
2977
2977
|
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
2978
2978
|
const [dropdownPosition, setDropdownPosition] = useState("bottom");
|
|
2979
2979
|
const containerRef = useRef(null);
|
|
2980
|
+
const dropdownRef = useRef(null);
|
|
2981
|
+
const dropdownPortalRef = useRef(null);
|
|
2980
2982
|
const [textInput, setTextInput] = useState(false);
|
|
2981
2983
|
const [error2, setError] = useState(void 0);
|
|
2982
2984
|
useEffect(() => {
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
+
dropdownPortalRef.current = document.createElement("div");
|
|
2986
|
+
document.body.appendChild(dropdownPortalRef.current);
|
|
2987
|
+
return () => {
|
|
2988
|
+
if (dropdownPortalRef.current) {
|
|
2989
|
+
document.body.removeChild(dropdownPortalRef.current);
|
|
2990
|
+
}
|
|
2991
|
+
};
|
|
2992
|
+
}, []);
|
|
2993
|
+
const updateDropdownPosition = useCallback(() => {
|
|
2994
|
+
if (!containerRef.current || !dropdownRef.current || !dropdownPortalRef.current) return;
|
|
2995
|
+
const containerRect = containerRef.current.getBoundingClientRect();
|
|
2996
|
+
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
|
|
2997
|
+
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
2998
|
+
const offset = 4;
|
|
2999
|
+
const top = containerRect.top + scrollTop + (dropdownPosition === "bottom" ? containerRect.height - offset : -dropdownRef.current.offsetHeight - offset);
|
|
3000
|
+
const left2 = containerRect.left + scrollLeft;
|
|
3001
|
+
Object.assign(dropdownPortalRef.current.style, {
|
|
3002
|
+
position: "absolute",
|
|
3003
|
+
top: `${top}px`,
|
|
3004
|
+
left: `${left2}px`,
|
|
3005
|
+
width: `${containerRect.width}px`,
|
|
3006
|
+
zIndex: "9999"
|
|
3007
|
+
});
|
|
3008
|
+
}, [dropdownPosition]);
|
|
3009
|
+
useEffect(() => {
|
|
3010
|
+
if (isDropdownOpen) {
|
|
3011
|
+
updateDropdownPosition();
|
|
3012
|
+
window.addEventListener("resize", updateDropdownPosition);
|
|
2985
3013
|
}
|
|
2986
|
-
|
|
2987
|
-
|
|
3014
|
+
return () => {
|
|
3015
|
+
window.removeEventListener("resize", updateDropdownPosition);
|
|
3016
|
+
};
|
|
3017
|
+
}, [isDropdownOpen, updateDropdownPosition]);
|
|
3018
|
+
const updateDropdownPositionBasedOnSpace = () => {
|
|
2988
3019
|
if (!containerRef.current) return;
|
|
2989
3020
|
const rect = containerRef.current.getBoundingClientRect();
|
|
2990
3021
|
const spaceBelow = window.innerHeight - rect.bottom;
|
|
@@ -2994,11 +3025,11 @@ const FSelectSearchDb = ({
|
|
|
2994
3025
|
};
|
|
2995
3026
|
useEffect(() => {
|
|
2996
3027
|
if (isDropdownOpen) {
|
|
2997
|
-
|
|
2998
|
-
window.addEventListener("resize",
|
|
3028
|
+
updateDropdownPositionBasedOnSpace();
|
|
3029
|
+
window.addEventListener("resize", updateDropdownPositionBasedOnSpace);
|
|
2999
3030
|
}
|
|
3000
3031
|
return () => {
|
|
3001
|
-
window.removeEventListener("resize",
|
|
3032
|
+
window.removeEventListener("resize", updateDropdownPositionBasedOnSpace);
|
|
3002
3033
|
};
|
|
3003
3034
|
}, [isDropdownOpen]);
|
|
3004
3035
|
const handlerOnChange = (e) => {
|
|
@@ -3129,7 +3160,17 @@ const FSelectSearchDb = ({
|
|
|
3129
3160
|
}
|
|
3130
3161
|
)
|
|
3131
3162
|
] }),
|
|
3132
|
-
isDropdownOpen && (arrObject.length > 0 || valueInput.trim() === "") &&
|
|
3163
|
+
isDropdownOpen && (arrObject.length > 0 || valueInput.trim() === "") && dropdownPortalRef.current && createPortal(
|
|
3164
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
3165
|
+
"div",
|
|
3166
|
+
{
|
|
3167
|
+
ref: dropdownRef,
|
|
3168
|
+
className: `${styles$e["f-select-search-db__dropdown"]} ${isDropdownOpen ? styles$e.active : ""}`,
|
|
3169
|
+
children: arrObject.length === 0 && valueInput.trim() === "" ? /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "Введите текст" }) : arrObject.length === 0 && valueInput.trim() !== "" && !load ? /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "Ничего не найдено" }) : /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: styles$e["f-select-search-db__dropdown_content"], children: arrObject.slice(0, 10).map((opt, index) => /* @__PURE__ */ jsxRuntimeExports.jsx("li", { onClick: () => handleItemClick(opt), children: selectItem(opt) }, index)) })
|
|
3170
|
+
}
|
|
3171
|
+
),
|
|
3172
|
+
dropdownPortalRef.current
|
|
3173
|
+
)
|
|
3133
3174
|
]
|
|
3134
3175
|
}
|
|
3135
3176
|
);
|