Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend/builder): skip Escape-to-close when focus is in textarea/input

Zamil Majdy57c0c86a10a6
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/useBuilderChatPanel.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/useBuilderChatPanel.ts
index 4c50386744..23e61b9c2d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/useBuilderChatPanel.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/useBuilderChatPanel.ts
@@ -308,6 +308,7 @@ export function useBuilderChatPanel({
// Close the panel on Escape when focus is inside the panel, so pressing Escape
// in another dialog or canvas element does not accidentally close the chat panel.
+ // Skip when focus is in an editable element to avoid discarding a draft in progress.
useEffect(() => {
if (!isOpen) return;
function onKeyDown(e: globalThis.KeyboardEvent) {
@@ -318,6 +319,13 @@ export function useBuilderChatPanel({
!panelRef.current.contains(e.target as Node)
)
return;
+ const target = e.target as HTMLElement;
+ if (
+ target.tagName === "TEXTAREA" ||
+ target.tagName === "INPUT" ||
+ target.isContentEditable
+ )
+ return;
setIsOpen(false);
}
document.addEventListener("keydown", onKeyDown);