Skip to content

Commit 7d28b93

Browse files
committed
Add helper to use view transition
1 parent 8241ae3 commit 7d28b93

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

app/helpers/turbo/drive_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ def turbo_page_requires_reload
4343
provide :head, turbo_page_requires_reload_tag
4444
end
4545

46+
# Configure whether to use the View Transitions API when navigating to a new page.
47+
# See +turbo_use_view_transition_tag+.
48+
def turbo_use_view_transition
49+
provide :head, turbo_use_view_transition_tag
50+
end
51+
52+
4653
# See +turbo_page_requires_reload+.
4754
def turbo_page_requires_reload_tag
4855
tag.meta(name: "turbo-visit-control", content: "reload")
@@ -83,5 +90,10 @@ def turbo_refresh_scroll_tag(scroll = :reset)
8390
raise ArgumentError, "Invalid scroll option '#{scroll}'" unless scroll.in?(%i[ reset preserve ])
8491
tag.meta(name: "turbo-refresh-scroll", content: scroll)
8592
end
93+
94+
# See +turbo_use_view_transition+.
95+
def turbo_use_view_transition_tag
96+
tag.meta(name: "view-transition", content: "same-origin")
97+
end
8698
end
8799

test/drive/drive_helper_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class Turbo::DriveHelperTest < ActionDispatch::IntegrationTest
1616
assert_match(/<meta name="turbo-refresh-method" content="morph">/, @response.body)
1717
assert_match(/<meta name="turbo-refresh-scroll" content="preserve">/, @response.body)
1818
end
19+
20+
test "using view transition" do
21+
get trays_path
22+
assert_match(/<meta name="view-transition" content="same-origin">/, @response.body)
23+
end
1924
end
2025

2126
class Turbo::DriverHelperUnitTest < ActionView::TestCase
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<% turbo_exempts_page_from_cache %>
22
<% turbo_page_requires_reload %>
33
<%= turbo_refreshes_with method: :morph, scroll: :preserve %>
4+
<%= turbo_use_view_transition %>
45

56
<p>Not in the cache!</p>

0 commit comments

Comments
 (0)