The best way to control Claude Code, Codex and more from any computer or phone
fix(web): closing a composer menu on a touch tablet no longer opens the keyboard (#36325)
Julius Marminge committed
Nov 13, 2026 at 12:15 UTC
fa6326bf1b1600410d7ade1ef8513c04b113ea4c
2 files changed
+57
-8
apps/web/src/components/chat/ComposerPermissionsSection.browser.test.tsx
+45
@@ -7,12 +7,14 @@ import { render } from "../../../test/render";
7
import { ComposerHandleContext, type ComposerHandleRef } from "../../composerHandleContext";
8
import { ComposerContextPermissions } from "../ComposerContextPermissions";
9
import { Menu, MenuPopup, MenuTrigger } from "../ui/menu";
10
+import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
11
import {
12
focusRequestedPermission,
13
markOpenToPermissions,
14
useComposerMenuProps,
15
} from "./composerEventScope";
16
import { ComposerFooterModeControls, ComposerPermissionsSection } from "./ComposerFooterControls";
17
+import { ComposerPickerFooter } from "./ComposerModelEffort";
18
import { runtimeModeConfig, runtimeModeOptions } from "./runtimeModeConfig";
19
20
const options = runtimeModeOptions.map((mode) => ({ mode, ...runtimeModeConfig[mode] }));
@@ -95,6 +97,49 @@ it("returns focus to the editor after a pick", async () => {
97
await vi.waitFor(() => expect(handle.focusAtEnd).toHaveBeenCalled());
98
});
99
100
+// Mirrors the model picker: a composer popover whose footer nests the Permissions menu.
101
+function PickerWithPermissions() {
102
+ const [mode, setMode] = useState<RuntimeMode>("full-access");
103
+ const composerMenuProps = useComposerMenuProps();
104
+ return (
105
+ <>
106
+ <p>Timeline</p>
107
+ <Popover>
108
+ <PopoverTrigger>Model</PopoverTrigger>
109
+ <PopoverPopup {...composerMenuProps}>
110
+ <ComposerPickerFooter
111
+ traits={null}
112
+ runtimeMode={mode}
113
+ runtimeModeOptions={options}
114
+ onRuntimeModeChange={setMode}
115
+ />
116
+ </PopoverPopup>
117
+ </Popover>
118
+ </>
119
+ );
120
+}
121
+
122
+it("on a touch tablet, tapping outside the Permissions menu leaves the editor unfocused", async () => {
123
+ const realMatchMedia = window.matchMedia.bind(window);
124
+ using _touch = vi
125
+ .spyOn(window, "matchMedia")
126
+ .mockImplementation((query) => realMatchMedia(query === "(pointer: coarse)" ? "all" : query));
127
+ const { handle, ui } = withComposer(<PickerWithPermissions />);
128
+ await using screen = await render(ui, { router: false }); // no routes involved
129
+ await userEvent.click(screen.getByRole("button", { name: "Model" }));
130
+ await userEvent.click(page.getByRole("button", { name: "Permissions: Full access" }));
131
+ const fullAccess = page.getByRole("menuitemradio", { name: "Full access" });
132
+ await expect.element(fullAccess).toBeInTheDocument();
133
+ const permissionsTrigger = page.getByRole("button", { name: "Permissions: Full access" });
134
+ // The first outside tap closes the Permissions menu, the second the picker around it.
135
+ await userEvent.click(document.body, { position: { x: 1, y: 1 } });
136
+ await expect.element(fullAccess).not.toBeInTheDocument();
137
+ await userEvent.click(screen.getByText("Timeline"));
138
+ await expect.element(permissionsTrigger).not.toBeInTheDocument();
139
+ // Focusing the editor after a tap opens the on-screen keyboard on Android tablets.
140
+ expect(handle.focusAtEnd).not.toHaveBeenCalled();
141
+});
142
+
143
it("opens on the checked permission when composer.mode marked the trigger", async () => {
144
await using screen = await render(<OverflowMenu />, { router: false }); // no routes involved
145
const trigger = screen.getByRole("button", { name: "More" });
apps/web/src/components/chat/composerEventScope.ts
+12
-8
@@ -1,4 +1,5 @@
1
import { useComposerHandleContext } from "../../composerHandleContext";
2
+import { useMediaQuery } from "../../hooks/useMediaQuery";
3
4
const COMPOSER_FLOATING_LAYER_SELECTOR = [
5
'[data-composer-drawer-layer="true"]',
@@ -11,19 +12,22 @@ export const composerFloatingLayerProps = {
12
13
export function useComposerMenuProps() {
14
const composerRef = useComposerHandleContext();
15
+ const isCoarsePointer = useMediaQuery({ pointer: "coarse" });
16
17
return {
18
...composerFloatingLayerProps,
17
- finalFocus: composerRef
18
- ? () => {
19
- const activeElement = document.activeElement;
20
- if (activeElement !== document.body && !isInsideComposerFloatingLayer(activeElement)) {
19
+ // Focusing the editor on a touch device opens the on-screen keyboard, so the menu keeps its own focus return.
20
+ finalFocus:
21
+ composerRef && !isCoarsePointer
22
+ ? () => {
23
+ const activeElement = document.activeElement;
24
+ if (activeElement !== document.body && !isInsideComposerFloatingLayer(activeElement)) {
25
+ return false;
26
+ }
27
+ composerRef.current?.focusAtEnd();
28
return false;
29
}
23
- composerRef.current?.focusAtEnd();
24
- return false;
25
- }
26
- : undefined,
30
+ : undefined,
31
};
32
}
33