DEV Community

Discussion on: Creating A Custom, Accessible Drop Down

Collapse
 
skbhardwaj profile image
Shrikrishna BHARDWAJ

Hello Emma,

Great post indeed.
Just wanted to know, how would you close the dropdown if we click outside of the dropdown without selecting any option?

Thanks,

Collapse
 
kevsingh98 profile image
kevsingh98 • Edited
function _clickOutside() {
   document.addEventListener("click", function (event) {
     if (event.target.closest(".dropdown")) { //replace the class name to your needs
     return;
     }
     close(); //just calling a function that removes classList of isOpen
     }, false);
}

Hope this can help :)