File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -206,14 +206,18 @@ import "yet-another-react-lightbox/styles.css";
206206 <td>portal</td>
207207 <td>
208208 {<br />
209- root?: DocumentFragment | Element | null;<br />
209+ root?: (() => DocumentFragment | Element | null) | DocumentFragment | Element | null;<br />
210210 container?: React.HTMLAttributes<HTMLDivElement>;<br />
211211 }
212212 </td>
213213 <td>
214214 <p>Portal settings.</p>
215215 <ul>
216- <li>`root` - custom portal mount point. By default, the portal is mounted as a child of the document body.</li>
216+ <li>
217+ `root` - custom portal mount point. By default, the portal is mounted as a child of the document body.
218+ Can also be a function that returns the mount point - useful when targeting an element managed by a React
219+ ref (e.g. `root: () => portalRootRef.current`).
220+ </li>
217221 <li>`container` - HTML attributes for the portal container element (e.g., `{ dir: "rtl" }`).</li>
218222 </ul>
219223 </td>
Original file line number Diff line number Diff line change @@ -149,7 +149,7 @@ export function Portal({
149149 >
150150 { children }
151151 </ LightboxRoot > ,
152- root || document . body ,
152+ ( typeof root === "function" ? root ( ) : root ) || document . body ,
153153 )
154154 : null ;
155155}
Original file line number Diff line number Diff line change @@ -255,7 +255,7 @@ export interface ControllerRef {
255255/** Portal settings */
256256export interface PortalSettings {
257257 /** portal mount point */
258- root ?: DocumentFragment | Element | null ;
258+ root ?: ( ( ) => DocumentFragment | Element | null ) | DocumentFragment | Element | null ;
259259 /** HTML attributes for the portal container */
260260 container ?: React . HTMLAttributes < HTMLDivElement > ;
261261}
You can’t perform that action at this time.
0 commit comments