|
1 | | -import React from 'react'; |
| 1 | +import React, { useEffect, useRef } from 'react' |
2 | 2 |
|
3 | 3 | function CoursePagePopup({ isOpen, onClose, course, prerequisiteTree }) { |
| 4 | + |
| 5 | + const treeRef = useRef(null); |
| 6 | + useEffect(() => { |
| 7 | + const handleKeyDown = (event) => { |
| 8 | + if (event.key === 'Escape') { |
| 9 | + onClose(); |
| 10 | + } |
| 11 | + }; |
| 12 | + |
| 13 | + if (isOpen) { |
| 14 | + window.addEventListener('keydown', handleKeyDown); |
| 15 | + } |
| 16 | + |
| 17 | + return () => { |
| 18 | + window.removeEventListener('keydown', handleKeyDown); |
| 19 | + }; |
| 20 | + }, [isOpen, onClose]); |
| 21 | + |
| 22 | + const handleTreeClick = () => { |
| 23 | + if (treeRef.current) { |
| 24 | + treeRef.current.focus(); // gives it focus |
| 25 | + } |
| 26 | + }; |
| 27 | + |
4 | 28 | if (!isOpen || !course) return null; // Don't render if not open or course not selected |
5 | 29 | return ( |
6 | 30 | <div |
@@ -43,16 +67,26 @@ function CoursePagePopup({ isOpen, onClose, course, prerequisiteTree }) { |
43 | 67 | className="text-lg leading-8 text-[#2e2e4f] font-semibold tracking-wide prose prose-slate max-w-full" |
44 | 68 | dangerouslySetInnerHTML={{ __html: course.description }} |
45 | 69 | /> |
46 | | - |
| 70 | + |
47 | 71 | </div> |
48 | 72 |
|
49 | 73 | {/* Prerequisite Graph Tree Section */} |
50 | 74 | <div> |
51 | | - <h3 className="text-2xl font-semibold text-[#2e2e4f] mb-0.5">Prerequisite Graph Tree</h3> |
| 75 | + |
| 76 | + <h3 className="text-2xl font-semibold text-[#2e2e4f] mb-0.5"> |
| 77 | + Prerequisite Graph Tree |
| 78 | + </h3> |
52 | 79 | <div className="mb-4 h-0.5 w-full bg-violet-500"></div> |
53 | | - <div className="bg-indigo-300/50"> |
| 80 | + <div |
| 81 | + className="bg-indigo-300/50 outline-none focus:outline-none focus:ring-2 focus:ring-violet-600 rounded-lg transition-shadow" |
| 82 | + ref={treeRef} |
| 83 | + onClick={handleTreeClick} |
| 84 | + tabIndex={0} // allows the div to receive focus |
| 85 | + > |
54 | 86 | {prerequisiteTree} |
55 | 87 | </div> |
| 88 | + |
| 89 | + |
56 | 90 | </div> |
57 | 91 | {/* Reviews Section */} |
58 | 92 | <div> |
|
0 commit comments