Skip to content

Closing popovers programmatically? #6613

Answered by adidahiya
viveleroi asked this question in Q&A
Discussion options

You must be logged in to vote

I thought I could fake it by triggering document.body.click() but that doesn't seem to work. Are there any hooks or anything I can use to do this? I don't see anything noted in the docs.

Popovers use this Overlay behavior to close on document "mousedown" events:

if (this.props.canOutsideClickClose && !this.props.hasBackdrop) {
document.addEventListener("mousedown", this.handleDocumentClick);
}

You could try document.dispatchEvent(new MouseEvent("mousedown")) to close an open popover. This works for me on the Popover docs page:

popover-programmatic-close.mov

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by viveleroi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants