CurrentlyFocusedComponent is nullptr after giveAwayKeyboardFocus()

Hey all, having some trouble understanding the behaviour of keyboard focus, specifically what happens when focus is given away.

In the documentation it reads:

If this component or any of its children currently have the keyboard focus, this will defocus it, send a focus change notification, and try to pass the focus to the next component.

Can anyone help me understand where “(trying) to pass the focus to the next component” occurs in the code? For whatever reason, the focus is just passed to the top level window in our application despite there being plenty of available parent components in the hierarchy of the one losing focus. I don’t seem to have any problem with the focus if I pass keyboard focus to a sibling instead of using “giveAwayKeyboardFocus”, but I would prefer to understand the cause of this issue before making changes.

Any help is appreciated, cheers!