Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(a11y): close the composer's More input actions menu on Escape (#18174)

Engel Nystff1a1d64f7d7
diff --git a/__tests__/components/features/chat/components/chat-input-actions.test.tsx b/__tests__/components/features/chat/components/chat-input-actions.test.tsx
index fb3b6faf44..37eea70d0e 100644
--- a/__tests__/components/features/chat/components/chat-input-actions.test.tsx
+++ b/__tests__/components/features/chat/components/chat-input-actions.test.tsx
@@ -506,6 +506,25 @@ describe("ChatInputActions β€” More input actions overflow menu (#17925)", () =>
).not.toBeInTheDocument();
});
+ it("closes on Escape and returns focus to the trigger", () => {
+ renderWithProviders(<ChatInputActions disabled={false} />);
+
+ clickTrigger();
+ fireEvent.click(screen.getByTestId("overflow-model-button"));
+ fireEvent.keyDown(document, { key: "Escape" });
+
+ expect(getTrigger()).toHaveAttribute("aria-expanded", "false");
+ expect(
+ screen.queryByTestId("chat-input-overflow-menu"),
+ ).not.toBeInTheDocument();
+ expect(getTrigger()).toHaveFocus();
+
+ clickTrigger();
+ expect(
+ screen.getByTestId("overflow-model-submenu").parentElement,
+ ).not.toHaveClass("visible");
+ });
+
it("opens the Model submenu with the profile list", () => {
renderWithProviders(<ChatInputActions disabled={false} />);
diff --git a/src/components/features/chat/components/chat-input-actions.tsx b/src/components/features/chat/components/chat-input-actions.tsx
index 4616aced8a..27703daf64 100644
--- a/src/components/features/chat/components/chat-input-actions.tsx
+++ b/src/components/features/chat/components/chat-input-actions.tsx
@@ -37,6 +37,7 @@ import { ToolsContextMenuIconText } from "../../controls/tools-context-menu-icon
import { ContextMenuListItem } from "../../context-menu/context-menu-list-item";
import { ContextMenu } from "#/ui/context-menu";
import { useClickOutsideElement } from "#/hooks/use-click-outside-element";
+import { useCloseOnEscape } from "#/hooks/use-close-on-escape";
import { cn } from "#/utils/utils";
import {
chatInputIconButtonClassName,
@@ -262,6 +263,14 @@ export function ChatInputActions({
setIsOverflowOpen(false);
setActiveSubmenu(null);
}, overflowTriggerRef);
+ useCloseOnEscape(
+ isOverflowOpen,
+ () => {
+ setIsOverflowOpen(false);
+ setActiveSubmenu(null);
+ },
+ overflowTriggerRef,
+ );
const isAgentSwitcherDisabled =
curAgentState === AgentState.RUNNING ||