Skip to content

Commit

Permalink
refactor(listenFocusOutside): remove unnecessary code for old Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
lossir committed Apr 19, 2021
1 parent 9188cd1 commit d0196bd
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions packages/react-ui/lib/listenFocusOutside.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ReactDOM from 'react-dom';
import debounce from 'lodash.debounce';

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

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

function addHandleEvent() {
/**
* 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,
);
document.body.addEventListener('focusin', handleNativeFocus);
}

if (isBrowser) {
Expand Down

0 comments on commit d0196bd

Please sign in to comment.