This commit is contained in:
Yuhong Sun
2024-12-10 15:27:48 -08:00
committed by GitHub
parent 6d6e12119b
commit fe83f676df

View File

@@ -35,6 +35,13 @@ export function SetDefaultModelModal({
const container = containerRef.current; const container = containerRef.current;
const message = messageRef.current; const message = messageRef.current;
const handleEscape = (e: KeyboardEvent) => {
if (e.key === "Escape") {
onClose();
}
};
window.addEventListener("keydown", handleEscape);
if (container && message) { if (container && message) {
const checkScrollable = () => { const checkScrollable = () => {
if (container.scrollHeight > container.clientHeight) { if (container.scrollHeight > container.clientHeight) {
@@ -45,9 +52,14 @@ export function SetDefaultModelModal({
}; };
checkScrollable(); checkScrollable();
window.addEventListener("resize", checkScrollable); window.addEventListener("resize", checkScrollable);
return () => window.removeEventListener("resize", checkScrollable); return () => {
window.removeEventListener("resize", checkScrollable);
window.removeEventListener("keydown", handleEscape);
};
} }
}, []);
return () => window.removeEventListener("keydown", handleEscape);
}, [onClose]);
const defaultModelDestructured = defaultModel const defaultModelDestructured = defaultModel
? destructureValue(defaultModel) ? destructureValue(defaultModel)