-
Notifications
You must be signed in to change notification settings - Fork 116
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
Add turbo: true
as an option for ToggleSwitch
#2964
Conversation
🦋 Changeset detectedLatest commit: b0a1e30 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
2bc91ed
to
636faf9
Compare
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.
This looks great! Thanks
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.
Awesome, thank you!
@klaustopher would you mind adding a changeset? Run |
Will do tomorrow morning 👍 |
Changeset is added |
What are you trying to accomplish?
As described in #2940, we are using a
ToggleSwitchForm
and in our case the response is a turbo stream that should replace some other elements in the page. The current implementation does not allow for that as thefetch
request does not trigger any behavior associated with Turbo. To do that we need to explicitly set theAccept
header to allowtext/vnd.turbo-stream.html
and when the response comes back, we need to pass it toTurbo.renderStreamMessage
to be rendered.In #2940 we also discussed making the
ToggleSwitch
have a proper form, but while experimenting with this I found that this completely changes the existing behavior and I wanted this change to be as unobstrusive as it could be.Integration
The default is
turbo: false
, so nothing changes in existing code.List the issues that this change affects.
Closes #2940
Risk Assessment
The code does not change any default behavior. One has to intentionally activate turbo with
turbo: true
as a param to theToggleSwitch
to get the new behavior. Also the response needs to provide the correct content type to be forwarded into the turbo renderer.What approach did you choose and why?
See above
Anything you want to highlight for special attention from reviewers?
There are currently no tests for the call to
Turbo.renderStreamMessage
, would be interested in any pointers how to add proper tests.Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.