LG-14754: Avoid focus loss on submit button when submitting form#11482
Merged
LG-14754: Avoid focus loss on submit button when submitting form#11482
Conversation
For ARIA reflection: jsdom/jsdom#3655
changelog: Bug Fixes, Accessibility, Avoid focus loss on submit button when submitting form
aduth
commented
Nov 8, 2024
| } | ||
|
|
||
| handleLongWait() { | ||
| #handleLongWait = () => { |
Contributor
Author
There was a problem hiding this comment.
Taking more advantage of private class members, for clearer separate of public/private interface, and better bundle optimization (related Slack thread).
aduth
commented
Nov 8, 2024
|
|
||
| .usa-button:disabled.usa-button--active, | ||
| [aria-disabled='true'].usa-button--active { | ||
| .usa-button[aria-disabled='true'].usa-button--active { |
Contributor
Author
aduth
commented
Nov 8, 2024
| @@ -1,3 +1,4 @@ | |||
| import { mock } from 'node:test'; | |||
Contributor
Author
There was a problem hiding this comment.
Using node:test mock here instead of sinon because I think it might be possible to eventually move toward dropping Sinon in the future, this making that future work simpler.
Continuing to use Sinon in spinner-button-element.spec.ts for consistency's sake, since it's already used there.
aduth
commented
Nov 8, 2024
| "eslint-plugin-react-hooks": "^4.6.0", | ||
| "eslint-plugin-testing-library": "^6.2.0", | ||
| "jsdom": "^22.1.0", | ||
| "jsdom": "^25.0.1", |
Contributor
Author
There was a problem hiding this comment.
Update to be able to use HTMLElement#ariaDisabled in specs.
Rely on SubmitButtonElement to control whether submit event is emitted based on whether it's already being submitted
kevinsmaster5
approved these changes
Nov 8, 2024
Contributor
kevinsmaster5
left a comment
There was a problem hiding this comment.
LGTM, tested locally.
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.


🎫 Ticket
LG-14754
🛠 Summary of changes
Updates the behavior of submit buttons to avoid disabling the button using
disabledattribute, instead using a combination ofaria-disabledand event handlers to prevent duplicate submission when the button is already activated.This fixes an issue where focus loss can occur if the page's submit button is the active element when submitting the form. While this is usually not a problem because it's expected that the user will be navigated away after submitting the form, this can cause issues in some screen readers which announce the loss of focus (e.g. JAWS announcing "Unavailable").
📜 Testing Plan
Verify that focus is maintained when submitting a form, and that you cannot submit twice:
SpinnerButtonComponent:Apply diff to force a pause in submission and to validate duplicate submission handling, since form submission normally happens quickly:
SubmitButtonComponent:Apply diff to force a pause in submission and to validate duplicate submission handling, since form submission normally happens quickly: