I have created a simple package for collapsible elements with an option to close the element when clicked outside of it with an attribute data-close-on-click-outside
data-close-on-click-outside