Skip to content

Commit 526a148

Browse files
albertjimenezAlbert Sendrós
andauthored
#172 Fix X Close button: (#217)
- updated page.tsx to include an event listener for closing the modal when escape button is pressed Co-authored-by: Albert Sendrós <[email protected]>
1 parent 6c613a6 commit 526a148

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/app/[owner]/[repo]/page.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,24 @@ export default function RepoWikiPage() {
261261
}
262262
}, [currentPageId]);
263263

264+
// close the modal when escape is pressed
265+
useEffect(() => {
266+
const handleEsc = (event: KeyboardEvent) => {
267+
if (event.key === 'Escape') {
268+
setIsAskModalOpen(false);
269+
}
270+
};
271+
272+
if (isAskModalOpen) {
273+
window.addEventListener('keydown', handleEsc);
274+
}
275+
276+
// Cleanup on unmount or when modal closes
277+
return () => {
278+
window.removeEventListener('keydown', handleEsc);
279+
};
280+
}, [isAskModalOpen]);
281+
264282
// Fetch authentication status on component mount
265283
useEffect(() => {
266284
const fetchAuthStatus = async () => {

0 commit comments

Comments
 (0)