-
Notifications
You must be signed in to change notification settings - Fork 435
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
Configure Submitter disabling #1216
Conversation
@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)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @seanpdoyle
Follow-up to comment on [238ec26][] [hotwired#1216][] unintentionally removed support for the `Turbo.session.drive` boolean property and the `Turbo.session.formMode` string property. This commit re-introduces that support by delegating reads and writes to those properties to their corresponding `Turbo.config` versions. [hotwired#1216]: hotwired#1216 [238ec26]: hotwired@238ec26#commitcomment-145954235
Turbo 8 deprecated `Turbo.setConfirmMethod()` and instead moved it to `Turbo.config.forms.confirm` instead (see hotwired/turbo#1216). Because of that, avo is throwing deprecation messages in the javascript console: Please replace `Turbo.setConfirmMethod(confirmMethod)` with `Turbo.config.forms.confirm = confirmMethod`. The top-level function is deprecated and will be removed in a future version of Turbo. I've updated the code to use the new config object instead, which should resolve the deprecation warning.
Turbo 8 deprecated `Turbo.setConfirmMethod()` and instead moved it to `Turbo.config.forms.confirm` instead (see hotwired/turbo#1216). Because of that, avo is throwing deprecation messages in the javascript console: Please replace `Turbo.setConfirmMethod(confirmMethod)` with `Turbo.config.forms.confirm = confirmMethod`. The top-level function is deprecated and will be removed in a future version of Turbo. I've updated the code to use the new config object instead, which should resolve the deprecation warning.
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.