Control closing the menu if clicking outside
See original GitHub issuedownshift
version: 1.31.14node
version: 9npm
(oryarn
) version: 1.6.0
I’m looking for a way to prevent the menu from closing when clicking outside the menu.
Right now when you click outside the menu , handleToggle is always called and isOpen
set to false closing the menu. I’m looking to prevent this where I want to actually keep the menu open in some cases , is there anyway to achieve this ?
handleToggle = ({ isOpen, type }) => {
this.setState({ open: isOpen })
}
<Downshift
defaultIsOpen={open}
isOpen={open}
onStateChange={this.handleToggle}
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
javascript - How to close menu when clicking outside of the div?
I want to be able to close a popup menu when the user clicks outside. How can I accomplish this in pure JS?...
Read more >Closing on outside click | Kitty Giraudel
As part of the navigation on the Gorillas website, we needed a way to close the menu when clicking outside of it or...
Read more >jQuery: click outside to close menu - CodePen
jQuery: click outside to close menu. Click the button to toggle the dropodown menu. Then click outside dropdown menu to close. Toggle menu....
Read more >How to avoid dropdown menu to close menu items on clicking ...
In this article, We will use stropPropagation method to prevent the dropdown menu from closing the menu list.
Read more >Dismissing a React Dropdown Menu by Clicking Outside its ...
In the toggleDropdown method, after opening the dropdown menu via setState({dropdownVisible: true}) when clicking the trigger button, the NativeClickListener ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi! Look at the docs for how to use the stateReducer 👌
I’m having a similar issue, but I don’t understand the solution here.
My component looks like this:
I want it so that when you click on the
<input>
, it won’t close, but if you click outside then it will. I’m also using a portal.I’ve prevented the closing with a
stateReducer
:But now it won’t close when I click outside either. What’s the solution?