Actual Behavior:
CodePen (or steps to reproduce the issue): *
AngularJS Versions: *
Additional Information:
Shortcut to create a new CodePen Demo.
Note: * indicates required information. Without this information, your issue may be auto-closed.
Do not modify the titles or questions. Simply add your responses to the ends of the questions.
Add more lines if needed.
@Splaktar do you mind taking a look at that?
I'm able to reproduce. It loops fine when going forward, but when going backwards it just stops at the 1st tabindex and never loops over to the last tabindex.
@Splaktar Maybe it is worth to back port the focus trap from Angular Material.
This is how it is used in the dialog: https://github.com/angular/material2/blob/master/src/lib/dialog/dialog-container.ts#L132
The Focus Trap itself: https://github.com/angular/material2/blob/master/src/cdk/a11y/focus-trap/focus-trap.md
@marosoft that is an interesting and proven approach. However, I wonder if we can solve it in a way that doesn't involve bringing a lot of new code into the repo. Have you looked at any alternatives that are more simple? Did they present problems that only something like the CDK focus trap can solve?
I'm currently focused on P1 issues, but this P2 issue should get some of my time later this fall.

We have the above structure with top and bottom focus traps.
Our logic for "redirecting" the focus is flawed:
https://github.com/angular/material/blob/0e68c8b9430111c1644339d07ccdf3d7320d4ad7/src/components/dialog/dialog.js#L1075-L1077
The bottom focus trap moves the focus to the md-dialog and the next tab moves the focus to the first focusable element in the dialog (button in this case).
The top focus trap moves the focus to the md-dialog and the next shift+tab moves the focus to the md-dialog. So it just gets stuck there.
I've been investigating pulling in _getFirstTabbableElement() and _getLastTabbableElement() from cdk/a11y/focus-trap since we currently have no way of getting the last focusable element in a dialog. However, it means that I have to pull in most all of InteractivityChecker as well.
I can avoid pulling in @angular/cdk/platform, so thankfully the web doesn't expand any further than that.
I've currently got this running and refactored a bit to work as part of $mdUtil, but currently $mdUtil.getLastTabbableElement(element[0]) is always returning null. I'm working on debugging this atm.