mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	feat: close #976 esc to close modal
This commit is contained in:
		@@ -2,7 +2,7 @@ import styles from "./ui-lib.module.scss";
 | 
			
		||||
import LoadingIcon from "../icons/three-dots.svg";
 | 
			
		||||
import CloseIcon from "../icons/close.svg";
 | 
			
		||||
import { createRoot } from "react-dom/client";
 | 
			
		||||
import React from "react";
 | 
			
		||||
import React, { useEffect } from "react";
 | 
			
		||||
 | 
			
		||||
export function Popover(props: {
 | 
			
		||||
  children: JSX.Element;
 | 
			
		||||
@@ -64,6 +64,21 @@ interface ModalProps {
 | 
			
		||||
  onClose?: () => void;
 | 
			
		||||
}
 | 
			
		||||
export function Modal(props: ModalProps) {
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    const onKeyDown = (e: KeyboardEvent) => {
 | 
			
		||||
      if (e.key === "Escape") {
 | 
			
		||||
        props.onClose?.();
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    window.addEventListener("keydown", onKeyDown);
 | 
			
		||||
 | 
			
		||||
    return () => {
 | 
			
		||||
      window.removeEventListener("keydown", onKeyDown);
 | 
			
		||||
    };
 | 
			
		||||
    // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
			
		||||
  }, []);
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <div className={styles["modal-container"]}>
 | 
			
		||||
      <div className={styles["modal-header"]}>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user