Repository navigation
[DRAFT] FIX: Keep focus and announce errors when target creation fails - #3849
Closed
Darrell Chee (darrellchee) wants to merge 3 commits into
Closed
Darrell Chee (darrellchee) wants to merge 3 commits into
Darrell Chee (darrellchee) wants to merge 3 commits into
Conversation
…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>
Contributor
There was a problem hiding this comment.
🟡 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>
Contributor
|
duplicate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Fixes #3710.
When creating a target fails (for example, HTTPTarget rejecting
"not an HTTP request"withInvalid HTTP request line), three things go wrong for keyboard and screen-reader users:disabledwhile the request is in flight. The browser blurs a focused element when it becomes disabled, so focus falls to<body>and is never restored.MessageBaronly mounts when there is an error, and Fluent's MessageBar announces throughuseAnnounce, which needs anAriaLiveAnnouncerthe app does not provide.aria-invalidor a description.Changes (all in
frontend/)disabledFocusablewhile submitting (it keeps focus and getsaria-disabled). Cancel and the parameter fields stay enabled. Validation-disabled Create is still natively disabled, as before.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.CreateConverterDialog.aria-invalidandaria-describedbythrough a newParameterFieldvalidationMessageprop, without a second alert role. A field inside "Advanced settings" opens that section. Logic is in the newfieldErrorAttribution.ts.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):validationMessageon 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
mainat 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-commiton the changed files: pass.mockproject, CI settings (E2E_SEEDED_MODE=true): 201 tests. The new spec,config.spec.tsandnumeric-controls.spec.tspass 3 times in a row with--fail-on-flaky-tests.seededproject: 102 passed.converters.spec.ts:580and:743fail andoperations.spec.ts:82is flaky on my machine. All three behave the same on unmodifiedmain(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.