File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,26 @@ const App: FC = () => {
8787
8888 return ( ) : void => window . removeEventListener ( 'wheel' , wheelListener ) ;
8989 } , [ wheelListener ] ) ;
90+
91+ const keyboardListener = useCallback ( ( event : KeyboardEvent ) : void => {
92+ const currentSectionIndex = currentSectionIndexRef . current ;
93+
94+
95+ if ( event . key === 'ArrowLeft' && currentSectionIndex !== 0 ) {
96+ updateSectionIndex ( currentSectionIndex - 1 ) ;
97+ return ;
98+ }
99+
100+ if ( event . key === 'ArrowRight' && currentSectionIndex !== Sections . length - 1 ) {
101+ updateSectionIndex ( currentSectionIndex + 1 ) ;
102+ }
103+ } , [ ] ) ;
104+
105+ useEffect ( ( ) => {
106+ window . addEventListener ( 'keydown' , keyboardListener ) ;
107+
108+ return ( ) : void => window . removeEventListener ( 'keydown' , keyboardListener ) ;
109+ } , [ keyboardListener ] ) ;
90110
91111 const touchStartTimeRef = useRef < number > ( Date . now ( ) ) ;
92112 const touchStartRef = useRef < [ number , number ] > ( [ 0 , 0 ] ) ;
You can’t perform that action at this time.
0 commit comments