Skip to content

Commit ab9ddd7

Browse files
committed
fix(web): Tab from Permissions menu keeps focus inside model picker
1 parent 7e2b094 commit ab9ddd7

2 files changed

Lines changed: 68 additions & 46 deletions

File tree

‎apps/web/src/components/chat/ComposerModelEffort.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,14 @@ function PermissionsMenu(props: {
725725
setMenuOpen(false);
726726
}
727727
}}
728+
onKeyDown={(event) => {
729+
const modified = event.shiftKey || event.altKey || event.ctrlKey || event.metaKey;
730+
if (event.key !== "Tab" || modified) return;
731+
// Tab past the last footer item hits the popover's guard and focuses its trigger.
732+
event.preventDefault();
733+
setMenuOpen(false);
734+
triggerRef.current?.focus();
735+
}}
728736
>
729737
<ComposerPermissionsSection
730738
runtimeMode={props.runtimeMode}

‎apps/web/src/components/chat/ComposerPermissionsSection.browser.test.tsx‎

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -222,54 +222,54 @@ it("opens permissions directly from the context strip and applies a supported mo
222222
await expect.element(trigger).toHaveFocus();
223223
});
224224

225-
it("closes the nested Permissions menu when composer.effort moves focus to effort", async () => {
226-
const instanceId = ProviderInstanceId.make("codex");
227-
const entries = deriveProviderInstanceEntries([
228-
{
229-
instanceId,
230-
driver: ProviderDriverKind.make("codex"),
231-
enabled: true,
232-
installed: true,
233-
version: null,
234-
status: "ready",
235-
auth: { status: "authenticated" },
236-
checkedAt: "2026-01-01T00:00:00.000Z",
237-
models: [{ slug: "model-a", name: "Model A", isCustom: false, capabilities: {} }],
238-
slashCommands: [],
239-
skills: [],
240-
},
241-
]);
242-
const modelOptions = new Map(entries.map((entry) => [entry.instanceId, entry.models]));
225+
const instanceId = ProviderInstanceId.make("codex");
226+
const entries = deriveProviderInstanceEntries([
227+
{
228+
instanceId,
229+
driver: ProviderDriverKind.make("codex"),
230+
enabled: true,
231+
installed: true,
232+
version: null,
233+
status: "ready",
234+
auth: { status: "authenticated" },
235+
checkedAt: "2026-01-01T00:00:00.000Z",
236+
models: [{ slug: "model-a", name: "Model A", isCustom: false, capabilities: {} }],
237+
slashCommands: [],
238+
skills: [],
239+
},
240+
]);
241+
const modelOptions = new Map(entries.map((entry) => [entry.instanceId, entry.models]));
243242

244-
function Picker() {
245-
const [mode, setMode] = useState<RuntimeMode>("full-access");
246-
return (
247-
<ProviderModelPicker
248-
environmentId={null}
249-
activeInstanceId={instanceId}
250-
model="model-a"
251-
lockedProvider={null}
252-
instanceEntries={entries}
253-
modelOptionsByInstance={modelOptions}
254-
triggerAriaLabel="Choose model"
255-
onInstanceModelChange={() => {}}
256-
effortColumn={
257-
<button type="button" role="radio" aria-checked="true" data-effort-row data-effort-level>
258-
Medium
259-
</button>
260-
}
261-
footer={
262-
<ComposerPickerFooter
263-
traits={null}
264-
runtimeMode={mode}
265-
runtimeModeOptions={options}
266-
onRuntimeModeChange={setMode}
267-
/>
268-
}
269-
/>
270-
);
271-
}
243+
function Picker() {
244+
const [mode, setMode] = useState<RuntimeMode>("full-access");
245+
return (
246+
<ProviderModelPicker
247+
environmentId={null}
248+
activeInstanceId={instanceId}
249+
model="model-a"
250+
lockedProvider={null}
251+
instanceEntries={entries}
252+
modelOptionsByInstance={modelOptions}
253+
triggerAriaLabel="Choose model"
254+
onInstanceModelChange={() => {}}
255+
effortColumn={
256+
<button type="button" role="radio" aria-checked="true" data-effort-row data-effort-level>
257+
Medium
258+
</button>
259+
}
260+
footer={
261+
<ComposerPickerFooter
262+
traits={null}
263+
runtimeMode={mode}
264+
runtimeModeOptions={options}
265+
onRuntimeModeChange={setMode}
266+
/>
267+
}
268+
/>
269+
);
270+
}
272271

272+
it("closes the nested Permissions menu when composer.effort moves focus to effort", async () => {
273273
await using screen = await render(<Picker />);
274274
const trigger = screen.getByRole("button", { name: "Choose model" });
275275
await userEvent.click(trigger);
@@ -290,3 +290,17 @@ it("closes the nested Permissions menu when composer.effort moves focus to effor
290290
await expect.element(fullAccess).not.toBeInTheDocument();
291291
await expect.element(page.getByRole("radio", { name: "Medium" })).toHaveFocus();
292292
});
293+
294+
it("closes the nested Permissions menu on Tab and returns focus to its trigger", async () => {
295+
await using screen = await render(<Picker />);
296+
await userEvent.click(screen.getByRole("button", { name: "Choose model" }));
297+
const permissionsTrigger = page.getByRole("button", { name: "Permissions: Full access" });
298+
await userEvent.click(permissionsTrigger);
299+
const fullAccess = page.getByRole("menuitemradio", { name: "Full access" });
300+
await expect.element(fullAccess).toHaveFocus();
301+
302+
await userEvent.tab();
303+
304+
await expect.element(fullAccess).not.toBeInTheDocument();
305+
await expect.element(permissionsTrigger).toHaveFocus();
306+
});

0 commit comments

Comments
 (0)