You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge #8 to support SVG, by changing to create{Html,Svg}PortalNode
This is a breaking change, because createPortalNode is no longer
supported, and will be released as v2.0.0. To migrate, just
replace all v1 calls to createPortalNode with createHtmlPortalNode.
Closes#2.
@@ -104,11 +104,17 @@ Normally in `ComponentA`/`ComponentB` examples like the above, switching from `C
104
104
105
105
How does it work under the hood?
106
106
107
-
### `portals.createPortalNode`
107
+
### `portals.createHtmlPortalNode`
108
108
109
109
This creates a detached DOM node, with a little extra functionality attached to allow transmitting props later on.
110
110
111
-
This node will contain your portal contents later, and eventually be attached in the target location. By default it's a `div`, but you can pass your tag of choice (as a string) to override this if necessary. It's a plain DOM node, so you can mutate it to set any required props (e.g. `className`) with the standard DOM APIs.
111
+
This node will contain your portal contents later, within a `<div>`, and will eventually be attached in the target location. Its plain DOM node is available at `.element`, so you can mutate that to set any required props (e.g. `className`) with the standard DOM APIs.
112
+
113
+
### `portals.createSvgPortalNode`
114
+
115
+
This creates a detached SVG DOM node. It works identically to the node from `createHtmlPortalNode`, except it will work with SVG elements. Content is placed within a `<g>` instead of a `<div>`.
116
+
117
+
An error will be thrown if you attempt to use a HTML node for SVG content, or a SVG node for HTML content.
// To support SVG and other non-html elements, the portalNode's elementType needs to match
85
+
// the elementType it's being rendered into
86
+
if(newParent!==parent){
87
+
if(!validateElementType(newParent,elementType)){
88
+
thrownewError(`Invalid element type for portal: "${elementType}" portalNodes must be used with ${elementType} elements, but OutPortal is within <${newParent.tagName}>.`);
0 commit comments