Skip to content

Commit

Permalink
Merge pull request opf#13820 from opf/fix/correct-remove-action-logic…
Browse files Browse the repository at this point in the history
…-for-turbo-stream-response

Fix `:remove` action for component turbo stream responses
  • Loading branch information
aaron-contreras authored Oct 2, 2023
2 parents f5bd78e + c78a7ad commit b965eec
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/components/concerns/op_turbo/streamable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def render_as_turbo_stream(view_context:, action: :update)
when :replace
template = render_in(view_context)
when :remove
@wrapper_only = true
render_in(view_context)
template = nil
else
raise "Unsupported action #{action}"
Expand Down Expand Up @@ -79,13 +81,19 @@ def component_wrapper(tag: "div", class: nil, data: nil, style: nil, &block)
@component_wrapper_used = true
if inner_html_only?
capture(&block)
elsif wrapper_only?
content_tag(tag, id: wrapper_key, class:, data:, style:)
else
content_tag(tag, id: wrapper_key, class:, data:, style:, &block)
end
end

def inner_html_only?
@inner_html_only == true
!!@inner_html_only
end

def wrapper_only?
!!@wrapper_only
end

def wrapper_key
Expand Down

0 comments on commit b965eec

Please sign in to comment.