Handle `collapsed` class on triggers even when manually invoked

Fixes #13636.
I classified it as a utility function and followed the lead of the dropdown plugin, see https://github.com/twbs/bootstrap/blob/f75fc324622df92ffb0edef30dc87536dfba0b26/js/dropdown.js#L108-L119. I can make it an instance method, if you want me to.