Change keyboard focus

I have a pause menu with “Set Keyboard Focus” action so it can be used with gamepad and keyboard. But when opening a menu in the pause menu the focus stil lies in the pause menu, and not in the confirmination screen for example. How do I deactivate the focus when another menu is active? And then get the focus back when you cancel the menu and return to the pause menu?

Here’s an example of passing focus from one menu to another: