File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,9 +31,16 @@ function getContainer(context){
3131 domUtils . ownerDocument ( context ) . body ;
3232}
3333
34+
35+
36+ let currentFocusListener ;
37+
3438/**
3539 * Firefox doesn't have a focusin event so using capture is easiest way to get bubbling
3640 * IE8 can't do addEventListener, but does have onfocusin, so we use that in ie8
41+ *
42+ * We only allow one Listener at a time to avoid stack overflows
43+ *
3744 * @param {ReactElement|HTMLElement } context
3845 * @param {Function } handler
3946 */
@@ -42,14 +49,20 @@ function onFocus(context, handler) {
4249 let useFocusin = ! doc . addEventListener ;
4350 let remove ;
4451
52+ if ( currentFocusListener )
53+ currentFocusListener . remove ( ) ;
54+
4555 if ( useFocusin ) {
4656 document . attachEvent ( 'onfocusin' , handler ) ;
4757 remove = ( ) => document . detachEvent ( 'onfocusin' , handler ) ;
4858 } else {
4959 document . addEventListener ( 'focus' , handler , true ) ;
5060 remove = ( ) => document . removeEventListener ( 'focus' , handler , true ) ;
5161 }
52- return { remove } ;
62+
63+ currentFocusListener = { remove }
64+
65+ return currentFocusListener ;
5366}
5467
5568let scrollbarSize ;
You can’t perform that action at this time.
0 commit comments