-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure Submitter disabling #1216
Open
seanpdoyle
wants to merge
2
commits into
hotwired:main
Choose a base branch
from
seanpdoyle:config-disable-submitter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
@afcapel @jorgemanrubia this is inspired by #774, although it not mentioned directly. |
8807db4
to
cfb226b
Compare
This looks great! As a screen reader user I can confirm that this is a great improvement. Hopefully it can become the default for the next major version. |
The initial implementation aims to replace the ad hoc configurations spread across `window.Turbo` and `Turbo.session`. Those objects shouldn't be considered part of the public interface, especially for extension. This commit exports a single object from `src/core/config` to serve as a centralized, user-facing repository for configuration values. The main `src/core/config` object is composed of two constituent parts: * `src/core/config/drive` * `src/core/config/forms` In the future, the directory structure can be expanded upon to suit the needs of the project. Any user-facing configuration outside of `Turbo.config` is deprecated.
Follow-up to [hotwired#386][] While Turbo's support for disabling a Form Submissions `<input type="submit">` or `<button>` element is rooted in [Rails UJS][], it degrades (and has always degraded) the accessibility of those experiences. To learn more about the risks involved, read the [Don't Disable Submits][] section of Adrian Roselli's [Don't Disable Form Controls][] along with the additional resources mentioned therein. The risk of degrading accessibility is especially true for Morph-enabled Form Submissions. If a form submission will trigger a morphing Page Refresh with the submitter focused, it's likely that the focus *is intended to* remain on the submitter. With the current `[disabled]` behavior, that is not possible without a bespoke event handler like: ```js addEventListener("submit", ({ target, submitter }) => { if (submitter) { target.addEventListener("turbo:submit-start", () => { submitter.disabled = false submitter.focus() }, { once: true }) } }) ``` This commit introduces a `Turbo.config.forms.submitter` object with two pre-defined keys: `"disabled"` (the default until we can deprecate it), and `"aria-disabled"`. When applications specify either `Turbo.config.forms.submitter = "disabled"` or `Turbo.config.forms.submitter = "aria-disabled"`, they will be able to leverage those pre-packed hooks. Otherwise, they can provide their own object with `beforeSubmit(submitter)` and `afterSubmit(submitter)` functions. [hotwired#386]: hotwired#386 [Rails UJS]: https://guides.rubyonrails.org/v6.0/working_with_javascript_in_rails.html#automatic-disabling [Don't Disable Form Controls]: https://adrianroselli.com/2024/02/dont-disable-form-controls.html [Don't Disable Submits]: https://adrianroselli.com/2024/02/dont-disable-form-controls.html#Submit
cfb226b
to
145faee
Compare
@jorgemanrubia @brunoprietog are either of you able to review this proposal (as a follow-up to #1217)? |
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.
Depends on #1217
Follow-up to #386
While Turbo's support for disabling a Form Submissions
<input type="submit">
or<button>
element is rooted in Rails UJS, itdegrades (and has always degraded) the accessibility of those
experiences.
To learn more about the risks involved, read the Don't Disable
Submits section of Adrian Roselli's Don't Disable Form Controls
along with the additional resources mentioned therein.
The risk of degrading accessibility is especially true for Morph-enabled
Form Submissions. If a form submission will trigger a morphing Page
Refresh with the submitter focused, it's likely that the focus is
intended to remain on the submitter.
With the current
[disabled]
behavior, that is not possible without abespoke event handler like:
This commit introduces a
Turbo.config.forms.submitter
object with twopre-defined keys:
"disabled"
(the default until we can deprecate it),and
"aria-disabled"
.When applications specify either
Turbo.config.forms.submitter = "disabled"
orTurbo.config.forms.submitter = "aria-disabled"
, theywill be able to leverage those pre-packed hooks. Otherwise, they can
provide their own object with
beforeSubmit(submitter)
andafterSubmit(submitter)
functions.