11// src/components/dashboard/LeaderBoard/PRListModal.tsx
2- import React from "react" ;
2+ import React , { useEffect } from "react" ;
33import { motion , AnimatePresence } from "framer-motion" ;
44import { FaTimes , FaExternalLinkAlt , FaGithub } from "react-icons/fa" ;
55import { useColorMode } from "@docusaurus/theme-common" ;
@@ -64,12 +64,6 @@ export default function PRListModal({
6464 }
6565 } ;
6666
67- const handleKeyDown = ( e : React . KeyboardEvent ) => {
68- if ( e . key === "Escape" ) {
69- onClose ( ) ;
70- }
71- } ;
72-
7367 // Helper function to get filter display text
7468 const getFilterDisplayText = ( filter : string ) => {
7569 switch ( filter ) {
@@ -94,6 +88,21 @@ export default function PRListModal({
9488 return "#6b7280" ; // Gray for no points
9589 } ;
9690
91+ // Close modal on Escape key press
92+ useEffect ( ( ) => {
93+ if ( ! isOpen ) return ;
94+ const handleEsc = ( event : KeyboardEvent ) => {
95+ if ( event . key === "Escape" ) {
96+ onClose ( ) ;
97+ }
98+ } ;
99+
100+ window . addEventListener ( "keydown" , handleEsc ) ;
101+ return ( ) => {
102+ window . removeEventListener ( "keydown" , handleEsc ) ;
103+ } ;
104+ } , [ isOpen ] )
105+
97106 return (
98107 < AnimatePresence >
99108 { isOpen && (
@@ -103,7 +112,6 @@ export default function PRListModal({
103112 animate = { { opacity : 1 } }
104113 exit = { { opacity : 0 } }
105114 onClick = { handleBackdropClick }
106- onKeyDown = { handleKeyDown }
107115 tabIndex = { 0 }
108116 role = "dialog"
109117 aria-modal = "true"
0 commit comments