@idds/react 1.4.12 → 1.4.14

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/index.es.js CHANGED
@@ -2273,7 +2273,12 @@ function Dropdown({
2273
2273
  const [open, setOpen] = useState(false);
2274
2274
  const [dropdownPosition, setDropdownPosition] = useState({ vertical: "bottom", horizontal: "right" });
2275
2275
  const containerRef = useRef(null);
2276
+ const [mounted, setMounted] = useState(false);
2277
+ useEffect(() => {
2278
+ setMounted(true);
2279
+ }, []);
2276
2280
  useEffect(() => {
2281
+ if (!mounted) return;
2277
2282
  const handleClickOutside = (e) => {
2278
2283
  if (containerRef.current && !containerRef.current.contains(e.target)) {
2279
2284
  setOpen(false);
@@ -2283,7 +2288,7 @@ function Dropdown({
2283
2288
  return () => {
2284
2289
  document.removeEventListener("mousedown", handleClickOutside);
2285
2290
  };
2286
- }, []);
2291
+ }, [mounted]);
2287
2292
  const handleTriggerClick = (e) => {
2288
2293
  e.stopPropagation();
2289
2294
  if (disabled) return;
@@ -2294,7 +2299,21 @@ function Dropdown({
2294
2299
  const vertical = fitsBelow ? "bottom" : "top";
2295
2300
  const fitsRight = rect.right + dropdownWidth <= window.innerWidth;
2296
2301
  const horizontal = fitsRight ? "right" : "left";
2297
- setDropdownPosition({ vertical, horizontal });
2302
+ const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
2303
+ const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
2304
+ let top = 0;
2305
+ let left = 0;
2306
+ if (vertical === "bottom") {
2307
+ top = rect.bottom + scrollTop + 8;
2308
+ } else {
2309
+ top = rect.top + scrollTop - dropdownHeight - 8;
2310
+ }
2311
+ if (horizontal === "right") {
2312
+ left = rect.left + scrollLeft;
2313
+ } else {
2314
+ left = rect.right + scrollLeft - dropdownWidth;
2315
+ }
2316
+ setDropdownPosition({ vertical, horizontal, top, left });
2298
2317
  }
2299
2318
  setOpen((o) => !o);
2300
2319
  };
@@ -2310,36 +2329,40 @@ function Dropdown({
2310
2329
  `ina-dropdown__menu--align-${dropdownPosition.horizontal}`,
2311
2330
  dropdownClassName
2312
2331
  );
2313
- return /* @__PURE__ */ jsxs("div", { ref: containerRef, className: dropdownContainerClasses, children: [
2314
- /* @__PURE__ */ jsx("div", { onClick: handleTriggerClick, className: triggerClasses, children: trigger }),
2315
- open && /* @__PURE__ */ jsx(
2316
- "div",
2317
- {
2318
- className: menuClasses,
2319
- style: {
2320
- width: dropdownWidth,
2321
- ...dropdownStyle
2322
- },
2323
- role: "menu",
2324
- onMouseDown: (e) => e.stopPropagation(),
2325
- children: /* @__PURE__ */ jsx("ul", { className: "ina-dropdown__list", children: items.map((item, idx) => {
2326
- if (item && typeof item === "object" && "props" in item && item.props.className) {
2327
- return /* @__PURE__ */ jsx("li", {
2328
- role: "none",
2329
- // Clone element dengan className hasil clsx
2330
- // @ts-ignore
2331
- children: React.cloneElement(item, {
2332
- className: clsx(
2333
- "ina-dropdown__item",
2334
- item.props.className
2335
- )
2336
- })
2337
- }, idx);
2338
- }
2339
- return /* @__PURE__ */ jsx("li", { role: "none", children: /* @__PURE__ */ jsx("div", { className: "ina-dropdown__item", children: item }) }, idx);
2340
- }) })
2341
- }
2342
- )
2332
+ const menuContent = open && mounted ? /* @__PURE__ */ jsx(
2333
+ "div",
2334
+ {
2335
+ className: menuClasses,
2336
+ style: {
2337
+ width: dropdownWidth,
2338
+ position: "absolute",
2339
+ top: dropdownPosition.top,
2340
+ left: dropdownPosition.left,
2341
+ ...dropdownStyle
2342
+ },
2343
+ role: "menu",
2344
+ onMouseDown: (e) => e.stopPropagation(),
2345
+ children: /* @__PURE__ */ jsx("ul", { className: "ina-dropdown__list", children: items.map((item, idx) => {
2346
+ if (item && typeof item === "object" && "props" in item && item.props.className) {
2347
+ return /* @__PURE__ */ jsx("li", {
2348
+ role: "none",
2349
+ // Clone element dengan className hasil clsx
2350
+ // @ts-ignore
2351
+ children: React.cloneElement(item, {
2352
+ className: clsx(
2353
+ "ina-dropdown__item",
2354
+ item.props.className
2355
+ )
2356
+ })
2357
+ }, idx);
2358
+ }
2359
+ return /* @__PURE__ */ jsx("li", { role: "none", children: /* @__PURE__ */ jsx("div", { className: "ina-dropdown__item", children: item }) }, idx);
2360
+ }) })
2361
+ }
2362
+ ) : null;
2363
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2364
+ /* @__PURE__ */ jsx("div", { ref: containerRef, className: dropdownContainerClasses, children: /* @__PURE__ */ jsx("div", { onClick: handleTriggerClick, className: triggerClasses, children: trigger }) }),
2365
+ mounted && createPortal(menuContent, document.body)
2343
2366
  ] });
2344
2367
  }
2345
2368
  const ALLOWED_MIME_TYPES = {