@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-multi-select",
3
- "version": "0.185.4",
3
+ "version": "0.185.6",
4
4
  "main": "./web/index.js",
5
5
  "module": "./web/index.mjs",
6
6
  "types": "./web/index.d.ts",
@@ -10,10 +10,10 @@
10
10
  "build:native": "PLATFORM=native tsup"
11
11
  },
12
12
  "dependencies": {
13
- "@xsolla/xui-checkbox": "0.185.4",
14
- "@xsolla/xui-core": "0.185.4",
15
- "@xsolla/xui-dropdown": "0.185.4",
16
- "@xsolla/xui-primitives-core": "0.185.4"
13
+ "@xsolla/xui-checkbox": "0.185.6",
14
+ "@xsolla/xui-core": "0.185.6",
15
+ "@xsolla/xui-dropdown": "0.185.6",
16
+ "@xsolla/xui-primitives-core": "0.185.6"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": ">=16.8.0",
package/web/index.js CHANGED
@@ -1765,13 +1765,23 @@ var useMultiSelectControl = ({
1765
1765
  const isPlaceholder = !selectedItems || selectedItems.length === 0;
1766
1766
  (0, import_react8.useEffect)(() => {
1767
1767
  if (!containerRef.current) return;
1768
- const resizeObserver = new ResizeObserver((entries) => {
1769
- for (const entry of entries) {
1770
- setItemsWidth(entry.contentRect.width);
1771
- }
1772
- });
1768
+ let rafId = null;
1769
+ const syncItemsWidth = () => {
1770
+ rafId = null;
1771
+ if (!containerRef.current) return;
1772
+ const width = containerRef.current.getBoundingClientRect().width;
1773
+ setItemsWidth((prev) => prev === width ? prev : width);
1774
+ };
1775
+ const scheduleWidthSync = () => {
1776
+ if (rafId != null) return;
1777
+ rafId = requestAnimationFrame(syncItemsWidth);
1778
+ };
1779
+ const resizeObserver = new ResizeObserver(scheduleWidthSync);
1773
1780
  resizeObserver.observe(containerRef.current);
1774
- return () => resizeObserver.disconnect();
1781
+ return () => {
1782
+ if (rafId != null) cancelAnimationFrame(rafId);
1783
+ resizeObserver.disconnect();
1784
+ };
1775
1785
  }, [containerRef]);
1776
1786
  const widthsDependencies = (0, import_react8.useMemo)(
1777
1787
  () => ({
@@ -2334,25 +2344,32 @@ var MultiSelect = (0, import_react12.forwardRef)(
2334
2344
  overflow: "hidden",
2335
2345
  textOverflow: "ellipsis"
2336
2346
  };
2337
- const updateMenuPosition = (0, import_react12.useCallback)(() => {
2338
- if (!isWeb || !controlRef.current) return;
2339
- const rect = controlRef.current.getBoundingClientRect();
2340
- setMenuPosition({
2341
- left: rect.left,
2342
- top: rect.bottom + 4,
2343
- width: rect.width
2344
- });
2345
- }, []);
2346
2347
  (0, import_react12.useEffect)(() => {
2347
2348
  if (!isWeb || !controlMenuOpen || isDisable || !dropdownMenu) return;
2348
- updateMenuPosition();
2349
- window.addEventListener("resize", updateMenuPosition);
2350
- window.addEventListener("scroll", updateMenuPosition, true);
2349
+ let rafId = null;
2350
+ const repositionMenu = () => {
2351
+ rafId = null;
2352
+ if (!controlRef.current) return;
2353
+ const rect = controlRef.current.getBoundingClientRect();
2354
+ setMenuPosition({
2355
+ left: rect.left,
2356
+ top: rect.bottom + 4,
2357
+ width: rect.width
2358
+ });
2359
+ };
2360
+ const scheduleUpdate = () => {
2361
+ if (rafId != null) return;
2362
+ rafId = requestAnimationFrame(repositionMenu);
2363
+ };
2364
+ scheduleUpdate();
2365
+ window.addEventListener("resize", scheduleUpdate);
2366
+ window.addEventListener("scroll", scheduleUpdate, true);
2351
2367
  return () => {
2352
- window.removeEventListener("resize", updateMenuPosition);
2353
- window.removeEventListener("scroll", updateMenuPosition, true);
2368
+ if (rafId != null) cancelAnimationFrame(rafId);
2369
+ window.removeEventListener("resize", scheduleUpdate);
2370
+ window.removeEventListener("scroll", scheduleUpdate, true);
2354
2371
  };
2355
- }, [controlMenuOpen, dropdownMenu, isDisable, updateMenuPosition]);
2372
+ }, [controlMenuOpen, dropdownMenu, isDisable]);
2356
2373
  (0, import_react12.useEffect)(() => {
2357
2374
  if (!isWeb || !dropdownMenu || !isOpen || isDisable) return;
2358
2375
  const handleOutsideMouseDown = (event) => {