@xsolla/xui-multi-select 0.185.4 → 0.185.5

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/web/index.mjs CHANGED
@@ -3,8 +3,7 @@ import {
3
3
  forwardRef as forwardRef4,
4
4
  useRef as useRef4,
5
5
  useEffect as useEffect4,
6
- useState as useState4,
7
- useCallback as useCallback2
6
+ useState as useState4
8
7
  } from "react";
9
8
 
10
9
  // ../../foundation/primitives-web/src/Box.tsx
@@ -1740,13 +1739,23 @@ var useMultiSelectControl = ({
1740
1739
  const isPlaceholder = !selectedItems || selectedItems.length === 0;
1741
1740
  useEffect(() => {
1742
1741
  if (!containerRef.current) return;
1743
- const resizeObserver = new ResizeObserver((entries) => {
1744
- for (const entry of entries) {
1745
- setItemsWidth(entry.contentRect.width);
1746
- }
1747
- });
1742
+ let rafId = null;
1743
+ const syncItemsWidth = () => {
1744
+ rafId = null;
1745
+ if (!containerRef.current) return;
1746
+ const width = containerRef.current.getBoundingClientRect().width;
1747
+ setItemsWidth((prev) => prev === width ? prev : width);
1748
+ };
1749
+ const scheduleWidthSync = () => {
1750
+ if (rafId != null) return;
1751
+ rafId = requestAnimationFrame(syncItemsWidth);
1752
+ };
1753
+ const resizeObserver = new ResizeObserver(scheduleWidthSync);
1748
1754
  resizeObserver.observe(containerRef.current);
1749
- return () => resizeObserver.disconnect();
1755
+ return () => {
1756
+ if (rafId != null) cancelAnimationFrame(rafId);
1757
+ resizeObserver.disconnect();
1758
+ };
1750
1759
  }, [containerRef]);
1751
1760
  const widthsDependencies = useMemo(
1752
1761
  () => ({
@@ -2309,25 +2318,32 @@ var MultiSelect = forwardRef4(
2309
2318
  overflow: "hidden",
2310
2319
  textOverflow: "ellipsis"
2311
2320
  };
2312
- const updateMenuPosition = useCallback2(() => {
2313
- if (!isWeb || !controlRef.current) return;
2314
- const rect = controlRef.current.getBoundingClientRect();
2315
- setMenuPosition({
2316
- left: rect.left,
2317
- top: rect.bottom + 4,
2318
- width: rect.width
2319
- });
2320
- }, []);
2321
2321
  useEffect4(() => {
2322
2322
  if (!isWeb || !controlMenuOpen || isDisable || !dropdownMenu) return;
2323
- updateMenuPosition();
2324
- window.addEventListener("resize", updateMenuPosition);
2325
- window.addEventListener("scroll", updateMenuPosition, true);
2323
+ let rafId = null;
2324
+ const repositionMenu = () => {
2325
+ rafId = null;
2326
+ if (!controlRef.current) return;
2327
+ const rect = controlRef.current.getBoundingClientRect();
2328
+ setMenuPosition({
2329
+ left: rect.left,
2330
+ top: rect.bottom + 4,
2331
+ width: rect.width
2332
+ });
2333
+ };
2334
+ const scheduleUpdate = () => {
2335
+ if (rafId != null) return;
2336
+ rafId = requestAnimationFrame(repositionMenu);
2337
+ };
2338
+ scheduleUpdate();
2339
+ window.addEventListener("resize", scheduleUpdate);
2340
+ window.addEventListener("scroll", scheduleUpdate, true);
2326
2341
  return () => {
2327
- window.removeEventListener("resize", updateMenuPosition);
2328
- window.removeEventListener("scroll", updateMenuPosition, true);
2342
+ if (rafId != null) cancelAnimationFrame(rafId);
2343
+ window.removeEventListener("resize", scheduleUpdate);
2344
+ window.removeEventListener("scroll", scheduleUpdate, true);
2329
2345
  };
2330
- }, [controlMenuOpen, dropdownMenu, isDisable, updateMenuPosition]);
2346
+ }, [controlMenuOpen, dropdownMenu, isDisable]);
2331
2347
  useEffect4(() => {
2332
2348
  if (!isWeb || !dropdownMenu || !isOpen || isDisable) return;
2333
2349
  const handleOutsideMouseDown = (event) => {