Hey, Gabriel. You’d need to have a click event on a div behind the component so that when you click outside it hides it. It also means that you’d need to have it sit at a higher z-index and positioned absolute to sit on top of other page elements.
That might be considered old school now and a bit faffy. You now have browser support for Popover API, which is worth checking out on MDN because you get that kind of stuff for free without adding extra complexity. Also, Andreas from the toddle team did a video on this on their YT channel.