When I make a button that turns on side menu I have to click the button again to turn it off. It is working this way because there are only first and second click interaction triggers. If there would be an option to trigger this interaction by clicking anywhere ourside an element it would be way more mogical and conveinient.
You can have an invisible div that fills up the entire screen when an interaction is triggered and add an interaction to that that will also close it. This is how this type of thing is usually done.