I have a situation where a user is able to open multiple independent dialogs. Intuitively, the dialog that has focus can be closed either by using the x icon or by pressing ESC.
After this dialog is closed, can the next dialog (based on the highest z-index) be given focus, so that the user could continue pressing ESC to close all their open dialogs?
Fiddle here. After loading, select any dialog, which you should be able to close by pressing ESC. The next highest dialog doesn’t get focus.
When the
closeevent occurs, check for thediv.ui-dialogthat is visible (closing a.ui-dialogwill simply hide the element) and has the highestz-index. Then set the focus on that dialog. This may not be the most efficient, but will work:An updated fiddle. Credit justkt’s answer regarding finding the element with the highest z-index using jQuery.