Skip to content

[DRAFT] FIX: Keep focus and announce errors when target creation fails - #3849

Closed
Darrell Chee (darrellchee) wants to merge 3 commits into
microsoft:mainfrom
darrellchee:fix/3710-create-target-error-focus
Closed

Darrell Chee (darrellchee) wants to merge 3 commits into
microsoft:mainfrom
darrellchee:fix/3710-create-target-error-focus

Conversation

@darrellchee

@darrellchee Darrell Chee (darrellchee) commented Nov 3, 2026 •

Copy link
Copy Markdown

Description

Fixes #3710.

When creating a target fails (for example, HTTPTarget rejecting "not an HTTP request" with Invalid HTTP request line), three things go wrong for keyboard and screen-reader users:

  1. Focus is lost. Create, Cancel and the parameter fields get native disabled while the request is in flight. The browser blurs a focused element when it becomes disabled, so focus falls to <body> and is never restored.
  2. The error is not announced. The error MessageBar only mounts when there is an error, and Fluent's MessageBar announces through useAnnounce, which needs an AriaLiveAnnouncer the app does not provide.
  3. The field is not marked invalid. Backend errors only reach a dialog-level string, so the Http Request field never gets aria-invalid or a description.

Changes (all in frontend/)

  • Focus stays in the dialog. Create uses disabledFocusable while submitting (it keeps focus and gets aria-disabled). Cancel and the parameter fields stay enabled. Validation-disabled Create is still natively disabled, as before.
  • Errors are announced. A role="alert" region is always mounted at the top of the form. The MessageBar inside is keyed by attempt, so an identical repeated error is announced again.
  • Focus moves to the error. After every failed submit, focus moves to that region. This follows the existing pattern in CreateConverterDialog.
  • The right field is marked invalid. An error is linked to a field only when exactly one rendered field's name or label appears in the message, and only for 400/422 responses and client-side parameter errors. Otherwise only the summary is shown; it never guesses. The field gets aria-invalid and aria-describedby through a new ParameterField validationMessage prop, without a second alert role. A field inside "Advanced settings" opens that section. Logic is in the new fieldErrorAttribution.ts.
  • Stale and duplicate requests are handled. A failure from a dialog opening the user already closed is ignored. A late success refreshes the target list without closing a reopened dialog. A second submit during an in-flight request is ignored.
  • e2e/numeric-controls.spec.ts: one locator now filters by text, because the dialog has an extra (empty) alert region.

Relation to #3831

#3831 also addresses this issue, with a smaller change focused on HTTPTarget. This PR takes a broader approach (a live region that exists before the error, re-announcing repeats, keeping focus during submit, generic field matching, and stale/duplicate request handling). Happy to coordinate with mikemikimike, or for maintainers to pick whichever approach fits best.

Tests and Documentation

New and updated tests:

  • CreateTargetDialog.test.tsx: submit-error accessibility suite (focus, live region, repeat announcement, field attribution, recovery, stale responses, double submit).
  • fieldErrorAttribution.test.ts (new): matching rules, including ambiguous and short names.
  • ParameterField.test.tsx (new): validationMessage on each field kind.
  • TargetConfig.test.tsx: late success after reopening.
  • e2e/target-create-errors.spec.ts (new): the issue's exact keyboard steps in a real browser. jsdom does not blur disabled elements, so focus loss only shows up here.

Local results on this branch (rebased on main at 0ffa2fc):

  • npm run lint, npx tsc --noEmit, npm run build: pass.
  • npm run test:coverage: 174 suites, 4,095 tests pass; coverage thresholds met.
  • pre-commit on the changed files: pass.
  • Playwright mock project, CI settings (E2E_SEEDED_MODE=true): 201 tests. The new spec, config.spec.ts and numeric-controls.spec.ts pass 3 times in a row with --fail-on-flaky-tests.
  • Playwright seeded project: 102 passed. converters.spec.ts:580 and :743 fail and operations.spec.ts:82 is flaky on my machine. All three behave the same on unmodified main (0ffa2fc), so they are not caused by this change.

No documentation changes: this restores expected dialog behaviour and adds no new user-facing options. JupyText not run, since no notebooks or Python code changed.

…soft#3710)

When creating a target failed (e.g. HTTPTarget rejecting "Invalid HTTP
request line"), keyboard focus fell to <body>, the error was never
announced, and the field it was about was not marked invalid.

- Keep the Create button focusable while a request is in flight
  (disabledFocusable instead of native disabled), and leave Cancel and
  the parameter fields enabled, so the browser has nothing to blur.
- Render an always-mounted role="alert" region at the top of the form and
  key the error MessageBar by attempt, so every failure (including an
  identical repeat) is announced. Fluent's MessageBar announce needs an
  AriaLiveAnnouncer the app does not provide.
- After every failed submit, move focus to that region (same pattern as
  CreateConverterDialog).
- Attribute an error to a field only when exactly one rendered field's
  name or label appears in it (400/422 responses and client-side
  parameter errors only); otherwise show the summary alone. The matched
  field gets aria-invalid and aria-describedby via a new
  ParameterField validationMessage prop, without a second alert role.
  An attributed field inside "Advanced settings" opens that section.
- Ignore responses from a dialog opening the user has already left: a
  stale failure is dropped and a stale success refreshes the target list
  without closing or resetting a reopened dialog.
- Ignore a second submit while one is in flight, and don't attribute an
  error to a field after the target type has changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 3, 2026 06:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A pending request’s stale 400 response can incorrectly mark an edited field invalid; submission-time field revision tracking and a deferred-response regression test are still needed.

1 open issue
What changed in this PR

Addresses #3710 by improving keyboard focus and accessible error feedback in PyRIT’s target-creation dialog.

Changes:

  • Preserves focus during submission and focuses a persistent alert region after failures.
  • Associates eligible errors with fields through shared validation support.
  • Handles duplicate submissions and responses from closed dialogs, with unit and browser regression coverage.
File Description
frontend/​src/​components/​Parameters/​validationMessageSlot.ts Adds validation messages without duplicate alert roles.
frontend/​src/​components/​Parameters/​ParameterField.tsx Supports externally attributed field errors.
frontend/​src/​components/​Parameters/​ParameterField.test.tsx Tests validation accessibility across control types.
frontend/​src/​components/​Config/​TargetConfig.tsx Refreshes targets without closing a reopened dialog.
frontend/​src/​components/​Config/​TargetConfig.test.tsx Tests current and stale creation callbacks.
frontend/​src/​components/​Config/​fieldErrorAttribution.ts Matches error messages to an unambiguous field.
frontend/​src/​components/​Config/​fieldErrorAttribution.test.ts Tests matching rules and ambiguity handling.
frontend/​src/​components/​Config/​CreateTargetDialog.tsx Adds accessible error handling and request lifecycle guards.
frontend/​src/​components/​Config/​CreateTargetDialog.test.tsx Expands focus, validation, and request lifecycle coverage.
frontend/​src/​components/​Config/​CreateTargetDialog.styles.ts Visually hides the empty alert while preserving accessibility.
frontend/​e2e/​target-create-errors.spec.ts Tests keyboard submission and focus in a browser.
frontend/​e2e/​numeric-controls.spec.ts Distinguishes weight errors from the new summary alert.

Review effort: Balanced

…quest

Fields stay editable while a create request is in flight. If the user
corrected the field the error names before the 400 arrived, the stale
error marked the corrected field invalid. Fields edited since the last
submit are now excluded from attribution; the summary still shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve conflicts with the new HelpField wrapper: ParameterField now renders
HelpField (help tooltip) and still passes the microsoft#3710 validationMessage and
validationState props through. Combine both versions of
ParameterField.test.tsx. Narrow the microsoft#3710 dialog tests' label queries to the
control, since HelpField adds an info button labelled by the field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@romanlutz

Copy link
Copy Markdown
Contributor

duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Target creation failure drops keyboard focus and does not announce the error

3 participants