Skip to content

Commit

Permalink
[fixed] Stack overflow with nested Modals
Browse files Browse the repository at this point in the history
fixes react-bootstrap#893 in the same way tbs fixes it, only allow one listener at a
time
  • Loading branch information
jquense committed Jun 29, 2015
1 parent ce3a1cd commit a8b177a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ function getContainer(context){
domUtils.ownerDocument(context).body;
}



let currentFocusListener;

/**
* Firefox doesn't have a focusin event so using capture is easiest way to get bubbling
* IE8 can't do addEventListener, but does have onfocusin, so we use that in ie8
*
* We only allow one Listener at a time to avoid stack overflows
*
* @param {ReactElement|HTMLElement} context
* @param {Function} handler
*/
Expand All @@ -42,14 +49,20 @@ function onFocus(context, handler) {
let useFocusin = !doc.addEventListener;
let remove;

if ( currentFocusListener )
currentFocusListener.remove();

if (useFocusin) {
document.attachEvent('onfocusin', handler);
remove = () => document.detachEvent('onfocusin', handler);
} else {
document.addEventListener('focus', handler, true);
remove = () => document.removeEventListener('focus', handler, true);
}
return { remove };

currentFocusListener = { remove }

return currentFocusListener;
}

let scrollbarSize;
Expand Down

0 comments on commit a8b177a

Please sign in to comment.