Skip to content

Commit

Permalink
refactor(listenFocusOutside): revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lossir committed May 6, 2021
1 parent 4bf82bc commit 2e9dee9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/react-ui/lib/listenFocusOutside.ts
@@ -1,6 +1,7 @@
import ReactDOM from 'react-dom';
import debounce from 'lodash.debounce';

import { isBrowser } from './client';
import { isBrowser, isFirefox } from './client';

interface FocusOutsideEventHandler {
elements: HTMLElement[] | (() => HTMLElement[]);
Expand All @@ -10,7 +11,19 @@ interface FocusOutsideEventHandler {
const handlers: FocusOutsideEventHandler[] = [];

function addHandleEvent() {
document.body.addEventListener('focusin', handleNativeFocus, { capture: true });
/**
* Firefox do not supports 'focusin' event.
* Focus events bubbles multiple time
* without possibilty to cancell bubbling.
* Using debounce to capture only first focus event
* Mozilla Firefix
* ¯\_(ツ)_/¯
*/
document.body.addEventListener(
isFirefox ? 'focus' : ('focusin' as 'focus'),
isFirefox ? debounce(handleNativeFocus, 0, { leading: true, trailing: false }) : handleNativeFocus,
isFirefox,
);
}

if (isBrowser) {
Expand Down

0 comments on commit 2e9dee9

Please sign in to comment.