Skip to content

Commit 523abd8

Browse files
authored
Merge pull request reactjs#275 from darrenscerri/portal-mounting
Update Portal Example: Render Modal children when Modal is inserted in the DOM tree
2 parents 85cfdc9 + f3fdc9b commit 523abd8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

content/docs/portals.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ This includes event bubbling. An event fired from inside a portal will propagate
6565

6666
A `Parent` component in `#app-root` would be able to catch an uncaught, bubbling event from the sibling node `#modal-root`.
6767

68-
```js{20-23,34-41,45,53-55,62-63,66}
68+
```js{28-31,42-49,53,61-63,70-71,74}
6969
// These two containers are siblings in the DOM
7070
const appRoot = document.getElementById('app-root');
7171
const modalRoot = document.getElementById('modal-root');
@@ -77,6 +77,14 @@ class Modal extends React.Component {
7777
}
7878
7979
componentDidMount() {
80+
// The portal element is inserted in the DOM tree after
81+
// the Modal's children are mounted, meaning that children
82+
// will be mounted on a detached DOM node. If a child
83+
// component requires to be attached to the DOM tree
84+
// immediately when mounted, for example to measure a
85+
// DOM node, or uses 'autoFocus' in a descendant, add
86+
// state to Modal and only render the children when Modal
87+
// is inserted in the DOM tree.
8088
modalRoot.appendChild(this.el);
8189
}
8290

0 commit comments

Comments
 (0)