Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portal only renders children after mounted #1913

Merged
merged 3 commits into from
Dec 14, 2017
Merged

Portal only renders children after mounted #1913

merged 3 commits into from
Dec 14, 2017

Conversation

giladgray
Copy link
Contributor

Fixes #1901

componentDidMount() {
    // The portal element is inserted in the DOM tree after
    // the Modal's children are mounted, meaning that children
    // will be mounted on a detached DOM node. If a child
    // component requires to be attached to the DOM tree
    // immediately when mounted, for example to measure a
    // DOM node, or uses 'autoFocus' in a descendant, add
    // state to Modal and only render the children when Modal
    // is inserted in the DOM tree.
    modalRoot.appendChild(this.el);
}

(https://reactjs.org/docs/portals.html#event-bubbling-through-portals)

@@ -357,9 +359,6 @@ export class Overlay extends React.PureComponent<IOverlayProps, IOverlayState> {
if (this.props.isOpen) {
safeInvoke(this.props.didOpen);
}
if (this.props.autoFocus) {
this.bringFocusInsideOverlay();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed as overlayWillOpen is invoked shortly afterward for first render and then for every subsequent open, whereas this is only called after initial mount.

if (this.props.canOutsideClickClose && !this.props.hasBackdrop) {
document.addEventListener("mousedown", this.handleDocumentClick);
if (this.props.autoFocus) {
this.bringFocusInsideOverlay();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should happen when not inline too, so I moved it to a more logical order in the method.

@blueprint-bot
Copy link

Select autoFocus on InputGroup

Preview: documentation

@adidahiya adidahiya merged commit 225758c into master Dec 14, 2017
@adidahiya adidahiya deleted the gg/autofocus branch December 14, 2017 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants