-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change/close dropdown when clicked outside (#37169)
* Close Action button dropdown when clicked outside * changelog
- Loading branch information
1 parent
002b870
commit 9b64103
Showing
5 changed files
with
38 additions
and
3 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
23 changes: 23 additions & 0 deletions
23
projects/packages/my-jetpack/_inc/hooks/use-outside-alerter/index.ts
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,23 @@ | ||
import { useEffect } from 'react'; | ||
import type { MutableRefObject } from 'react'; | ||
|
||
const useOutsideAlerter = ( ref: MutableRefObject< HTMLElement >, onClickOutside: () => void ) => { | ||
useEffect( () => { | ||
const handleClickOutside = ( event: Event ) => { | ||
if ( | ||
event.target instanceof Element && | ||
ref.current && | ||
! ref.current.contains( event.target ) | ||
) { | ||
onClickOutside(); | ||
} | ||
}; | ||
|
||
document.addEventListener( 'mousedown', handleClickOutside ); | ||
return () => { | ||
document.removeEventListener( 'mousedown', handleClickOutside ); | ||
}; | ||
}, [ ref, onClickOutside ] ); | ||
}; | ||
|
||
export default useOutsideAlerter; |
4 changes: 4 additions & 0 deletions
4
projects/packages/my-jetpack/changelog/change-close-dropdown-when-clicked-outside
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,4 @@ | ||
Significance: patch | ||
Type: changed | ||
|
||
Fix z-index issue and close action button dropdown when clicked outside |