-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed the behavior of dropdown list when clicked outside of its …
…scope (#1838) * Fixed the behavior of dropdownlist when clicked outside of its scope. * removed unwanted console.log * Fixed a bug * removed unnecessary console.log() * Restricted topbar icons to inherit click-outside functionality --------- Co-authored-by: Rupali Haldiya <[email protected]>
- Loading branch information
1 parent
82e83b9
commit b1eec4b
Showing
8 changed files
with
68 additions
and
13 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
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,32 @@ | ||
import { MutableRefObject, useEffect } from 'react' | ||
|
||
const useOnClickOutside = ( | ||
ref: MutableRefObject<HTMLUListElement | null>, | ||
handler: () => void | ||
) => { | ||
useEffect(() => { | ||
const handleClickOutside = (event: MouseEvent) => { | ||
if ( | ||
event.target && | ||
(event.target as HTMLElement)?.closest('[data-custom="restrict-click-outside"]') !== null) { | ||
return | ||
} | ||
|
||
if ( | ||
ref.current && | ||
!ref.current.classList.contains('copy-to-clipboard-button') && | ||
!ref.current.contains(event.target as Node) | ||
) { | ||
handler() | ||
} | ||
} | ||
|
||
document.addEventListener('mousedown', handleClickOutside) | ||
|
||
return () => { | ||
document.removeEventListener('mousedown', handleClickOutside) | ||
} | ||
}, [ref, handler]) | ||
} | ||
|
||
export default useOnClickOutside |
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
b1eec4b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
linkshub – ./
linkshub.vercel.app
linkshub-rupali-codes.vercel.app
linkshub-git-main-rupali-codes.vercel.app
www.linkshub.dev
linkshub.dev