Dialog: Search the correct document for focus trapping. Fixes #9439

Can I get a sanity check on this?