Yes, right clicking anywhere on the UI closes containers. Right clicking the inventory slots does not (presumably to avoid issues with miss-clicks in the inventory, and keep the player and container inventory slots consistent).