-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 implement useClickAway, remove useOutsideClick
This re-implements outside click hook functionality from scratch, removes dependency on use-onoutsideclick package. BREAKING CHANGE: 🧨 useOutsideClick is now useClickAway
- Loading branch information
Showing
7 changed files
with
30 additions
and
25 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
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,17 @@ | ||
import {RefObject, useEffect} from 'react'; | ||
import {on, off} from './util'; | ||
|
||
const useClickAway = (ref: RefObject<HTMLElement | null>, onClickAway: () => void) => { | ||
useEffect(() => { | ||
const handler = (event) => { | ||
const {current: el} = ref; | ||
el && !el.contains(event.target) && onClickAway(); | ||
}; | ||
on(document, 'click', handler); | ||
return () => { | ||
off(document, 'click', handler); | ||
}; | ||
}); | ||
}; | ||
|
||
export default useClickAway; |
This file was deleted.
Oops, something went wrong.