I'm not sure what is happening. I can replicate that behavior only when I disable javascript. If that case you can't close it as it relies on the url hash.
I don't have JavaScript disabled on any device. As an aside, it is possible to implement your feature without JavaScript (with <details> and <summary>).