Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #3 from nevir/infinite-recursion-fix
Browse files Browse the repository at this point in the history
Protect against infinite recursion in focusOverlay
  • Loading branch information
Steve Orvell committed Aug 4, 2014
2 parents 34a82a4 + 2e88d17 commit 9588c61
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions core-overlay.html
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ <h2>Dialog</h2>
},

openedChanged: function() {
this.transitioning = true;
this.ensureTargetSetup();
this.prepareRenderOpened();
// continue styling after delay so display state can change
Expand Down Expand Up @@ -371,6 +372,7 @@ <h2>Dialog</h2>
if (e && e.target !== this.target) {
return;
}
this.transitioning = false;
if (!this.opened) {
this.resetTargetDimensions();
this.target.style.display = 'none';
Expand Down Expand Up @@ -437,7 +439,11 @@ <h2>Dialog</h2>
focusNode.focus();
} else {
focusNode.blur();
focusOverlay();
if (currentOverlay() == this) {
console.warn('Current core-overlay is attempting to focus itself as next! (bug)');
} else {
focusOverlay();
}
}
},

Expand Down Expand Up @@ -637,7 +643,15 @@ <h2>Dialog</h2>

function focusOverlay() {
var current = currentOverlay();
if (current) {
// We have to be careful to focus the next overlay _after_ any current
// transitions are complete (due to the state being toggled prior to the
// transition). Otherwise, we risk infinite recursion when a transitioning
// (closed) overlay becomes the current overlay.
//
// NOTE: We make the assumption that any overlay that completes a transition
// will call into focusOverlay to kick the process back off. Currently:
// transitionend -> applyFocus -> focusOverlay.
if (current && !current.transitioning) {
current.applyFocus();
}
}
Expand Down

0 comments on commit 9588c61

Please sign in to comment.