Skip to content

Commit

Permalink
🛠️ Component: ButtonComponent supports GET Turbo Streams
Browse files Browse the repository at this point in the history
- #1187
- https://turbo.hotwired.dev/handbook/streams#streaming-from-http-responses

It turns out that `Turbo` only does turbo-streams when
`PUT`/`POST`/`DELETE` are the request methods.

If we want to make `GET` requests use the `turbo-stream` request type,
we need to specify it in the HTML output, i.e. `<a href="..."
data-turbo-stream=true>`

I wasn't sure if this should be default behavior or not, so I leaned
towards making it default to not 🤷
  • Loading branch information
zspencer committed Apr 2, 2023
1 parent 77a01bf commit 002e347
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/components/button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def initialize(
method: :put,
confirm: nil,
disabled: false,
classes: nil
classes: nil,
turbo_stream: nil
)
@label = label
@title = title
Expand All @@ -17,6 +18,7 @@ def initialize(
@confirm = confirm
@disabled = disabled
@classes = classes
@turbo_stream = turbo_stream
end

attr_accessor :classes
Expand All @@ -25,6 +27,7 @@ def initialize(

def data
data = {turbo_method: @method, turbo: true}
data[:turbo_stream] = true if @turbo_stream
if @confirm.present?
data[:turbo_confirm] = @confirm
data[:confirm] = @confirm
Expand Down

0 comments on commit 002e347

Please sign in to comment.