Fix getActiveDialog to accept different appendTo values #558
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The getActiveDialog private function is currently used to handle the TAB key in case trapFocus is true. The function returns the last '.ngdialog' in the DOM, which is normally the active dialog, but as noted in a comment in the source code, this doesn't work in case of mixed 'appendTo' values. You might be opening a second dialog somewhere before in the DOM which is actually the active one, because due to a higher z-index value it's the one being shown on the top.
This caused the TAB key not to work properly in those cases of mixed 'appendTo' values. Here's a demo of the problem: https://jsfiddle.net/r6fr5wz0/
Click on "open second dialog" and then press TAB. The result will be that the focus goes back to the first dialog (as it is the active one according to getActiveDialog for being the latest in the DOM) while the expected behaviour would be to stay in the second one.
My PR fixes this problem. It goes over the openIdStack getting the highest z-index. In case it's the same among two dialogs, then it checks the order in the DOM. This makes getActiveDialog always return the topmost dialog.
The previous demo with my PR applied: https://jsfiddle.net/55jwo3sb/