The current-implemented behavior can be an issue in cases where the dialog has been opened programmatically (e.g. triggered by some other event) and the originally-focused element ("opener" in the code, a misnomer in this case) is not visible within its scroll parent or the viewport.
Closing the dialog will scroll the element into view even though it wasn't before.
The culprit is here:
The call to .focus() should not be done inside the conditional, but there should instead be a step to store the scrollTop/scrollLeft of the scroll parent just before the focus, then restore it after the focus (perhaps conditionally, depending on whether or not the element was already visible).
Does this sound reasonable? Should this be reopened, or should I copy-paste this as a new issue? Thoughts?