From 157de15c3f05712aa392fb1954756427c84392a7 Mon Sep 17 00:00:00 2001 From: jay23606 <4602056+jay23606@users.noreply.github.com> Date: Wed, 4 Nov 2026 06:47:48 -0500 Subject: [PATCH] Restore focus to the objective opener when its dialog closes --- .../Scenarios/ScenarioRunPage.test.tsx | 35 +++++++++++++++++++ .../components/Scenarios/ScenarioRunPage.tsx | 10 +++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/Scenarios/ScenarioRunPage.test.tsx b/frontend/src/components/Scenarios/ScenarioRunPage.test.tsx index 431bb5f3b0..4d02abaac0 100644 --- a/frontend/src/components/Scenarios/ScenarioRunPage.test.tsx +++ b/frontend/src/components/Scenarios/ScenarioRunPage.test.tsx @@ -216,6 +216,41 @@ describe('ScenarioRunPage', () => { await waitFor(() => expect(screen.getByRole('button', { name: 'First objective' })).toHaveFocus()) }) + it('restores focus to the objective opener when the objective dialog closes', async () => { + const user = userEvent.setup() + render() + const objective = screen.getByRole('button', { name: 'First objective' }) + await user.click(objective) + const dialog = within(await screen.findByRole('dialog')) + await user.click(dialog.getByRole('button', { name: 'Close', exact: true })) + await waitFor(() => expect(objective).toHaveFocus()) + }) + + it('restores focus to the objective opener after Escape and on reopening', async () => { + const user = userEvent.setup() + render() + const objective = screen.getByRole('button', { name: 'First objective' }) + await user.click(objective) + await screen.findByRole('dialog') + await user.keyboard('{Escape}') + await waitFor(() => expect(objective).toHaveFocus()) + await user.click(objective) + await screen.findByRole('dialog') + await user.keyboard('{Escape}') + await waitFor(() => expect(objective).toHaveFocus()) + }) + + it('restores focus to the technique opener when attack details are dismissed with Escape', async () => { + const user = userEvent.setup() + render() + await expand(user) + const details = screen.getAllByRole('button', { name: /^Open details for PromptSendingAttack:/ })[0] + await user.click(details) + await screen.findByRole('dialog') + await user.keyboard('{Escape}') + await waitFor(() => expect(details).toHaveFocus()) + }) + it('shows per-group and per-objective success rates without restoring paired outcomes', () => { render() expect(within(screen.getByLabelText('Scan summary')).getByText('50%', { exact: true })).toBeInTheDocument() diff --git a/frontend/src/components/Scenarios/ScenarioRunPage.tsx b/frontend/src/components/Scenarios/ScenarioRunPage.tsx index ccaa19709f..473012521b 100644 --- a/frontend/src/components/Scenarios/ScenarioRunPage.tsx +++ b/frontend/src/components/Scenarios/ScenarioRunPage.tsx @@ -209,6 +209,14 @@ function ScenarioRunContent({ scenarioResultId, attackResultId }: ScenarioRunCon }) } + const closeObjective = (): void => { + setObjective(null) + requestAnimationFrame(() => { + const trigger = objectiveTrigger.current + if (trigger?.isConnected) trigger.focus() + }) + } + const openAttemptDetails = ( attempt: ScenarioProgressResult | ScenarioHierarchyNode, trigger: HTMLElement, @@ -587,7 +595,7 @@ function ScenarioRunContent({ scenarioResultId, attackResultId }: ScenarioRunCon - { setObjective(null) }} +