Create a Dropdown in React that Closes When the Body is Clicked

added by JavaScript Kicks
12/24/2018 8:36:47 AM

287 Views

One common interaction with dropdowns is closing when anything else on the page is clicked. Within React though with controlled dropdowns that are shown by updating state you need to add additional code in order to properly setup this interaction. We also need to be sure and close the menu when the button is clicked rather than re-opening it.


0 comments