forked from primefaces/primereact
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix primefaces#4704: Image preview popup not closing on escape button…
… click (primefaces#4705) * Fix primfaces#4704 Image preview popup not closing on escape button click * Fix primfaces#4704 Resolved PR comments to run prettier * Fix primfaces#4704 Added useOnEscape hook in Dialog to resolve PR comments * Fix primfaces#4704 Reused the hook on dialog and sidebar components to resolve pr comments * Fix primfaces#4704 Added params code to dialog escape event click to resolve pr comments * renamed escape hook to resolve pr comments * fix: primefaces#4750, Added closeOnEscape to Overlay panel --------- Co-authored-by: akshayantony55 <akshayantony55@gmail.com>
- Loading branch information
1 parent
9dbd6b4
commit 1c97331
Showing
11 changed files
with
88 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as React from 'react'; | ||
import { useEventListener } from './useEventListener'; | ||
|
||
export const useOnEscapeKey = (ref, condition, callback) => { | ||
const handleEsc = (event) => { | ||
if (event.key === 'Esc' || event.key === 'Escape') { | ||
event.stopImmediatePropagation(); | ||
callback(event); | ||
} | ||
|
||
return; | ||
}; | ||
|
||
const [bindKeyDownListener, unbindKeyDownListener] = useEventListener({ | ||
type: 'keydown', | ||
listener: handleEsc | ||
}); | ||
|
||
React.useEffect(() => { | ||
if (!condition) { | ||
return; | ||
} | ||
|
||
if (!ref.current) { | ||
return; | ||
} | ||
|
||
bindKeyDownListener(); | ||
|
||
return () => { | ||
unbindKeyDownListener(); | ||
}; | ||
}); | ||
|
||
return [ref, callback]; | ||
}; |
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