Skip to content

Commit e6dd60b

Browse files
committed
[Bug Fix] Move ruby-ui-toaster id from turbo-frame to <ol>
turbo_stream.append('ruby-ui-toaster') was injecting toasts INSIDE the turbo-frame wrapper but as siblings of the <ol>. The MutationObserver in toaster_controller watches the <ol>, so new toasts were never tracked and never animated in. Drop the turbo-frame wrapper (refresh:morph wasn't actually wired to flash on navigation anyway) and put the target id on the <ol> itself. Now Turbo Stream appends land where the controller can see them.
1 parent 18a4dd8 commit e6dd60b

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

gem/lib/ruby_ui/toast/toast_region.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
module RubyUI
44
class ToastRegion < Base
5-
register_element :turbo_frame, tag: "turbo-frame"
6-
75
SKELETON_VARIANTS = %i[default success error warning info loading].freeze
86
POSITIONS = %i[top_left top_center top_right bottom_left bottom_center bottom_right].freeze
97

@@ -38,13 +36,11 @@ def initialize(
3836
end
3937

4038
def view_template(&block)
41-
turbo_frame(id: "ruby-ui-toaster", refresh: "morph", target: "_top") do
42-
ol(**attrs) do
43-
render_flash if @flash
44-
yield(self) if block
45-
end
46-
SKELETON_VARIANTS.each { |v| skeleton(v) }
39+
ol(**attrs) do
40+
render_flash if @flash
41+
yield(self) if block
4742
end
43+
SKELETON_VARIANTS.each { |v| skeleton(v) }
4844
end
4945

5046
private
@@ -80,6 +76,7 @@ def skeleton(variant)
8076

8177
def default_attrs
8278
{
79+
id: "ruby-ui-toaster",
8380
role: "region",
8481
aria_label: "Notifications",
8582
aria_live: "polite",

gem/test/ruby_ui/toast_region_test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
require "test_helper"
44

55
class RubyUI::ToastRegionTest < ComponentTest
6-
def test_renders_turbo_frame_with_id
6+
def test_renders_ol_with_target_id
77
out = phlex { RubyUI.ToastRegion() }
8-
assert_match(/<turbo-frame[^>]+id="ruby-ui-toaster"/, out)
9-
assert_match(/refresh="morph"/, out)
8+
assert_match(/<ol[^>]+id="ruby-ui-toaster"/, out)
109
end
1110

1211
def test_position_attr

0 commit comments

Comments
 (0)