-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed bug when the user couldn't blur from input in the Settings…
… Drawer
- Loading branch information
1 parent
42d5a86
commit 92831fa
Showing
4 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {RefObject, useEffect} from 'react'; | ||
|
||
type AnyEvent = MouseEvent | TouchEvent; | ||
|
||
export const useOnClickOutside = (ref: RefObject<any>, touchEndCb: (event: AnyEvent) => void): void => { | ||
useEffect(() => { | ||
const onTouchEndListener = (event: AnyEvent) => { | ||
const el = ref?.current; | ||
|
||
if (!el || el.contains(event.target as Node)) { | ||
return; | ||
} | ||
|
||
touchEndCb(event); | ||
}; | ||
|
||
document.addEventListener(`mouseup`, onTouchEndListener); | ||
document.addEventListener(`touchend`, onTouchEndListener); | ||
|
||
return () => { | ||
document.removeEventListener(`mouseup`, onTouchEndListener); | ||
document.removeEventListener(`touchend`, onTouchEndListener); | ||
}; | ||
}, [ref, touchEndCb]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters