@xsolla/xui-multi-select 0.185.4 → 0.185.6
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/native/index.js +38 -21
- package/native/index.js.map +1 -1
- package/native/index.mjs +39 -23
- package/native/index.mjs.map +1 -1
- package/package.json +5 -5
- package/web/index.js +38 -21
- package/web/index.js.map +1 -1
- package/web/index.mjs +39 -23
- package/web/index.mjs.map +1 -1
package/native/index.mjs
CHANGED
|
@@ -3,8 +3,7 @@ import {
|
|
|
3
3
|
forwardRef as forwardRef4,
|
|
4
4
|
useRef as useRef4,
|
|
5
5
|
useEffect as useEffect3,
|
|
6
|
-
useState as useState3
|
|
7
|
-
useCallback as useCallback2
|
|
6
|
+
useState as useState3
|
|
8
7
|
} from "react";
|
|
9
8
|
|
|
10
9
|
// ../../foundation/primitives-native/src/Box.tsx
|
|
@@ -1700,13 +1699,23 @@ var useMultiSelectControl = ({
|
|
|
1700
1699
|
const isPlaceholder = !selectedItems || selectedItems.length === 0;
|
|
1701
1700
|
useEffect(() => {
|
|
1702
1701
|
if (!containerRef.current) return;
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1702
|
+
let rafId = null;
|
|
1703
|
+
const syncItemsWidth = () => {
|
|
1704
|
+
rafId = null;
|
|
1705
|
+
if (!containerRef.current) return;
|
|
1706
|
+
const width = containerRef.current.getBoundingClientRect().width;
|
|
1707
|
+
setItemsWidth((prev) => prev === width ? prev : width);
|
|
1708
|
+
};
|
|
1709
|
+
const scheduleWidthSync = () => {
|
|
1710
|
+
if (rafId != null) return;
|
|
1711
|
+
rafId = requestAnimationFrame(syncItemsWidth);
|
|
1712
|
+
};
|
|
1713
|
+
const resizeObserver = new ResizeObserver(scheduleWidthSync);
|
|
1708
1714
|
resizeObserver.observe(containerRef.current);
|
|
1709
|
-
return () =>
|
|
1715
|
+
return () => {
|
|
1716
|
+
if (rafId != null) cancelAnimationFrame(rafId);
|
|
1717
|
+
resizeObserver.disconnect();
|
|
1718
|
+
};
|
|
1710
1719
|
}, [containerRef]);
|
|
1711
1720
|
const widthsDependencies = useMemo(
|
|
1712
1721
|
() => ({
|
|
@@ -2263,25 +2272,32 @@ var MultiSelect = forwardRef4(
|
|
|
2263
2272
|
overflow: "hidden",
|
|
2264
2273
|
textOverflow: "ellipsis"
|
|
2265
2274
|
};
|
|
2266
|
-
const updateMenuPosition = useCallback2(() => {
|
|
2267
|
-
if (!isWeb || !controlRef.current) return;
|
|
2268
|
-
const rect = controlRef.current.getBoundingClientRect();
|
|
2269
|
-
setMenuPosition({
|
|
2270
|
-
left: rect.left,
|
|
2271
|
-
top: rect.bottom + 4,
|
|
2272
|
-
width: rect.width
|
|
2273
|
-
});
|
|
2274
|
-
}, []);
|
|
2275
2275
|
useEffect3(() => {
|
|
2276
2276
|
if (!isWeb || !controlMenuOpen || isDisable || !dropdownMenu) return;
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2277
|
+
let rafId = null;
|
|
2278
|
+
const repositionMenu = () => {
|
|
2279
|
+
rafId = null;
|
|
2280
|
+
if (!controlRef.current) return;
|
|
2281
|
+
const rect = controlRef.current.getBoundingClientRect();
|
|
2282
|
+
setMenuPosition({
|
|
2283
|
+
left: rect.left,
|
|
2284
|
+
top: rect.bottom + 4,
|
|
2285
|
+
width: rect.width
|
|
2286
|
+
});
|
|
2287
|
+
};
|
|
2288
|
+
const scheduleUpdate = () => {
|
|
2289
|
+
if (rafId != null) return;
|
|
2290
|
+
rafId = requestAnimationFrame(repositionMenu);
|
|
2291
|
+
};
|
|
2292
|
+
scheduleUpdate();
|
|
2293
|
+
window.addEventListener("resize", scheduleUpdate);
|
|
2294
|
+
window.addEventListener("scroll", scheduleUpdate, true);
|
|
2280
2295
|
return () => {
|
|
2281
|
-
|
|
2282
|
-
window.removeEventListener("
|
|
2296
|
+
if (rafId != null) cancelAnimationFrame(rafId);
|
|
2297
|
+
window.removeEventListener("resize", scheduleUpdate);
|
|
2298
|
+
window.removeEventListener("scroll", scheduleUpdate, true);
|
|
2283
2299
|
};
|
|
2284
|
-
}, [controlMenuOpen, dropdownMenu, isDisable
|
|
2300
|
+
}, [controlMenuOpen, dropdownMenu, isDisable]);
|
|
2285
2301
|
useEffect3(() => {
|
|
2286
2302
|
if (!isWeb || !dropdownMenu || !isOpen || isDisable) return;
|
|
2287
2303
|
const handleOutsideMouseDown = (event) => {
|