File tree Expand file tree Collapse file tree
src/renderer/components/HotkeyHelp Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " vibe-playground" ,
33 "productName" : " Vibe Playground" ,
4- "version" : " 0.6.2 " ,
4+ "version" : " 0.6.3 " ,
55 "description" : " Terminal manager with integrated file browsing for multiple repositories" ,
66 "main" : " .webpack/main" ,
77 "private" : true ,
Original file line number Diff line number Diff line change @@ -73,4 +73,32 @@ describe('HotkeyHelp', () => {
7373 const rows = table ?. querySelectorAll ( 'tr' ) ;
7474 expect ( rows ?. length ) . toBe ( 7 ) ; // 7 shortcuts defined
7575 } ) ;
76+
77+ it ( 'should call onClose when Escape key is pressed' , ( ) => {
78+ const onClose = jest . fn ( ) ;
79+ render ( < HotkeyHelp isOpen = { true } onClose = { onClose } /> ) ;
80+
81+ fireEvent . keyDown ( document , { key : 'Escape' } ) ;
82+
83+ expect ( onClose ) . toHaveBeenCalledTimes ( 1 ) ;
84+ } ) ;
85+
86+ it ( 'should not respond to Escape key when modal is closed' , ( ) => {
87+ const onClose = jest . fn ( ) ;
88+ render ( < HotkeyHelp isOpen = { false } onClose = { onClose } /> ) ;
89+
90+ fireEvent . keyDown ( document , { key : 'Escape' } ) ;
91+
92+ expect ( onClose ) . not . toHaveBeenCalled ( ) ;
93+ } ) ;
94+
95+ it ( 'should clean up event listener on unmount' , ( ) => {
96+ const onClose = jest . fn ( ) ;
97+ const { unmount } = render ( < HotkeyHelp isOpen = { true } onClose = { onClose } /> ) ;
98+
99+ unmount ( ) ;
100+ fireEvent . keyDown ( document , { key : 'Escape' } ) ;
101+
102+ expect ( onClose ) . not . toHaveBeenCalled ( ) ;
103+ } ) ;
76104} ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,19 @@ const shortcuts = [
1717] ;
1818
1919export function HotkeyHelp ( { isOpen, onClose } : HotkeyHelpProps ) {
20+ React . useEffect ( ( ) => {
21+ if ( ! isOpen ) return ;
22+
23+ const handleKeyDown = ( e : KeyboardEvent ) => {
24+ if ( e . key === 'Escape' ) {
25+ onClose ( ) ;
26+ }
27+ } ;
28+
29+ document . addEventListener ( 'keydown' , handleKeyDown ) ;
30+ return ( ) => document . removeEventListener ( 'keydown' , handleKeyDown ) ;
31+ } , [ isOpen , onClose ] ) ;
32+
2033 if ( ! isOpen ) return null ;
2134
2235 const handleOverlayClick = ( e : React . MouseEvent ) => {
You can’t perform that action at this time.
0 commit comments