@radix-ui/react-portal 1.1.0-rc.1 → 1.1.0-rc.2

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.d.mts CHANGED
@@ -7,7 +7,7 @@ interface PortalProps extends PrimitiveDivProps {
7
7
  /**
8
8
  * An optional container where the portaled content should be appended.
9
9
  */
10
- container?: HTMLElement | null;
10
+ container?: Element | null;
11
11
  }
12
12
  declare const Portal: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<HTMLDivElement>>;
13
13
  declare const Root: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<HTMLDivElement>>;
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ interface PortalProps extends PrimitiveDivProps {
7
7
  /**
8
8
  * An optional container where the portaled content should be appended.
9
9
  */
10
- container?: HTMLElement | null;
10
+ container?: Element | null;
11
11
  }
12
12
  declare const Portal: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<HTMLDivElement>>;
13
13
  declare const Root: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<HTMLDivElement>>;
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ "use client";
2
3
  (() => {
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
@@ -33,10 +34,14 @@
33
34
  var React = __toESM(__require("react"));
34
35
  var import_react_dom = __toESM(__require("react-dom"));
35
36
  var import_react_primitive = __require("@radix-ui/react-primitive");
37
+ var import_react_use_layout_effect = __require("@radix-ui/react-use-layout-effect");
36
38
  var import_jsx_runtime = __require("react/jsx-runtime");
37
39
  var PORTAL_NAME = "Portal";
38
40
  var Portal = React.forwardRef((props, forwardedRef) => {
39
- const { container = globalThis?.document?.body, ...portalProps } = props;
41
+ const { container: containerProp, ...portalProps } = props;
42
+ const [mounted, setMounted] = React.useState(false);
43
+ (0, import_react_use_layout_effect.useLayoutEffect)(() => setMounted(true), []);
44
+ const container = containerProp || mounted && globalThis?.document?.body;
40
45
  return container ? import_react_dom.default.createPortal(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.div, { ...portalProps, ref: forwardedRef }), container) : null;
41
46
  });
42
47
  Portal.displayName = PORTAL_NAME;
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/Portal.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * Portal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'Portal';\n\ntype PortalElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface PortalProps extends PrimitiveDivProps {\n /**\n * An optional container where the portaled content should be appended.\n */\n container?: HTMLElement | null;\n}\n\nconst Portal = React.forwardRef<PortalElement, PortalProps>((props, forwardedRef) => {\n const { container = globalThis?.document?.body, ...portalProps } = props;\n return container\n ? ReactDOM.createPortal(<Primitive.div {...portalProps} ref={forwardedRef} />, container)\n : null;\n});\n\nPortal.displayName = PORTAL_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Portal;\n\nexport {\n Portal,\n //\n Root,\n};\nexport type { PortalProps };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAuB;AACvB,yBAAqB;AACrB,+BAA0B;AAsBE;AAd5B,MAAM,cAAc;AAWpB,MAAM,SAAe,iBAAuC,CAAC,OAAO,iBAAiB;AACnF,UAAM,EAAE,YAAY,YAAY,UAAU,MAAM,GAAG,YAAY,IAAI;AACnE,WAAO,YACH,iBAAAA,QAAS,aAAa,4CAAC,iCAAU,KAAV,EAAe,GAAG,aAAa,KAAK,cAAc,GAAI,SAAS,IACtF;AAAA,EACN,CAAC;AAED,SAAO,cAAc;AAIrB,MAAM,OAAO;",
4
+ "sourcesContent": ["import * as React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * Portal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'Portal';\n\ntype PortalElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface PortalProps extends PrimitiveDivProps {\n /**\n * An optional container where the portaled content should be appended.\n */\n container?: Element | null;\n}\n\nconst Portal = React.forwardRef<PortalElement, PortalProps>((props, forwardedRef) => {\n const { container: containerProp, ...portalProps } = props;\n const [mounted, setMounted] = React.useState(false);\n useLayoutEffect(() => setMounted(true), []);\n const container = containerProp || (mounted && globalThis?.document?.body);\n return container\n ? ReactDOM.createPortal(<Primitive.div {...portalProps} ref={forwardedRef} />, container)\n : null;\n});\n\nPortal.displayName = PORTAL_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Portal;\n\nexport {\n Portal,\n //\n Root,\n};\nexport type { PortalProps };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAuB;AACvB,yBAAqB;AACrB,+BAA0B;AAC1B,uCAAgC;AAyBJ;AAjB5B,MAAM,cAAc;AAWpB,MAAM,SAAe,iBAAuC,CAAC,OAAO,iBAAiB;AACnF,UAAM,EAAE,WAAW,eAAe,GAAG,YAAY,IAAI;AACrD,UAAM,CAAC,SAAS,UAAU,IAAU,eAAS,KAAK;AAClD,wDAAgB,MAAM,WAAW,IAAI,GAAG,CAAC,CAAC;AAC1C,UAAM,YAAY,iBAAkB,WAAW,YAAY,UAAU;AACrE,WAAO,YACH,iBAAAA,QAAS,aAAa,4CAAC,iCAAU,KAAV,EAAe,GAAG,aAAa,KAAK,cAAc,GAAI,SAAS,IACtF;AAAA,EACN,CAAC;AAED,SAAO,cAAc;AAIrB,MAAM,OAAO;",
6
6
  "names": ["ReactDOM"]
7
7
  }
package/dist/index.mjs CHANGED
@@ -1,11 +1,17 @@
1
+ "use client";
2
+
1
3
  // packages/react/portal/src/Portal.tsx
2
4
  import * as React from "react";
3
5
  import ReactDOM from "react-dom";
4
6
  import { Primitive } from "@radix-ui/react-primitive";
7
+ import { useLayoutEffect } from "@radix-ui/react-use-layout-effect";
5
8
  import { jsx } from "react/jsx-runtime";
6
9
  var PORTAL_NAME = "Portal";
7
10
  var Portal = React.forwardRef((props, forwardedRef) => {
8
- const { container = globalThis?.document?.body, ...portalProps } = props;
11
+ const { container: containerProp, ...portalProps } = props;
12
+ const [mounted, setMounted] = React.useState(false);
13
+ useLayoutEffect(() => setMounted(true), []);
14
+ const container = containerProp || mounted && globalThis?.document?.body;
9
15
  return container ? ReactDOM.createPortal(/* @__PURE__ */ jsx(Primitive.div, { ...portalProps, ref: forwardedRef }), container) : null;
10
16
  });
11
17
  Portal.displayName = PORTAL_NAME;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/Portal.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * Portal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'Portal';\n\ntype PortalElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface PortalProps extends PrimitiveDivProps {\n /**\n * An optional container where the portaled content should be appended.\n */\n container?: HTMLElement | null;\n}\n\nconst Portal = React.forwardRef<PortalElement, PortalProps>((props, forwardedRef) => {\n const { container = globalThis?.document?.body, ...portalProps } = props;\n return container\n ? ReactDOM.createPortal(<Primitive.div {...portalProps} ref={forwardedRef} />, container)\n : null;\n});\n\nPortal.displayName = PORTAL_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Portal;\n\nexport {\n Portal,\n //\n Root,\n};\nexport type { PortalProps };\n"],
5
- "mappings": ";AAAA,YAAY,WAAW;AACvB,OAAO,cAAc;AACrB,SAAS,iBAAiB;AAsBE;AAd5B,IAAM,cAAc;AAWpB,IAAM,SAAe,iBAAuC,CAAC,OAAO,iBAAiB;AACnF,QAAM,EAAE,YAAY,YAAY,UAAU,MAAM,GAAG,YAAY,IAAI;AACnE,SAAO,YACH,SAAS,aAAa,oBAAC,UAAU,KAAV,EAAe,GAAG,aAAa,KAAK,cAAc,GAAI,SAAS,IACtF;AACN,CAAC;AAED,OAAO,cAAc;AAIrB,IAAM,OAAO;",
4
+ "sourcesContent": ["import * as React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * Portal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'Portal';\n\ntype PortalElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface PortalProps extends PrimitiveDivProps {\n /**\n * An optional container where the portaled content should be appended.\n */\n container?: Element | null;\n}\n\nconst Portal = React.forwardRef<PortalElement, PortalProps>((props, forwardedRef) => {\n const { container: containerProp, ...portalProps } = props;\n const [mounted, setMounted] = React.useState(false);\n useLayoutEffect(() => setMounted(true), []);\n const container = containerProp || (mounted && globalThis?.document?.body);\n return container\n ? ReactDOM.createPortal(<Primitive.div {...portalProps} ref={forwardedRef} />, container)\n : null;\n});\n\nPortal.displayName = PORTAL_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Portal;\n\nexport {\n Portal,\n //\n Root,\n};\nexport type { PortalProps };\n"],
5
+ "mappings": ";;;AAAA,YAAY,WAAW;AACvB,OAAO,cAAc;AACrB,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAyBJ;AAjB5B,IAAM,cAAc;AAWpB,IAAM,SAAe,iBAAuC,CAAC,OAAO,iBAAiB;AACnF,QAAM,EAAE,WAAW,eAAe,GAAG,YAAY,IAAI;AACrD,QAAM,CAAC,SAAS,UAAU,IAAU,eAAS,KAAK;AAClD,kBAAgB,MAAM,WAAW,IAAI,GAAG,CAAC,CAAC;AAC1C,QAAM,YAAY,iBAAkB,WAAW,YAAY,UAAU;AACrE,SAAO,YACH,SAAS,aAAa,oBAAC,UAAU,KAAV,EAAe,GAAG,aAAa,KAAK,cAAc,GAAI,SAAS,IACtF;AACN,CAAC;AAED,OAAO,cAAc;AAIrB,IAAM,OAAO;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-portal",
3
- "version": "1.1.0-rc.1",
3
+ "version": "1.1.0-rc.2",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {
@@ -28,7 +28,7 @@
28
28
  "version": "yarn version"
29
29
  },
30
30
  "dependencies": {
31
- "@radix-ui/react-primitive": "1.1.0-rc.1"
31
+ "@radix-ui/react-primitive": "1.1.0-rc.2"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@types/react": "*",