Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/shared/_form_image_field.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<div data-file-preview-target="filename"
class="text-center text-sm text-gray-500 break-all max-w-[8rem]">
<%= if blob.present? && blob.respond_to?(:persisted?) && blob.persisted?
link_to(blob.filename.to_s, url_for(file), class: "underline")
link_to(blob.filename.to_s, url_for(file), class: "underline", target: "_blank", rel: "noopener")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This partial is rendered in every model's edit form via shared/_form_image_fields, so adding target: "_blank" here fixes the "navigates away and loses unsaved edits" report (#1511) across stories, resources, workshop variations, etc. in one place. Matches the new-tab behavior the show-page galleries already get from DisplayImagePresenter.

else
Comment on lines 82 to 84
"No file selected"
end
Expand Down
14 changes: 14 additions & 0 deletions spec/views/shared/_form_image_field.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require "rails_helper"

RSpec.describe "shared/_form_image_field", type: :view do
let(:asset) { create(:gallery_asset, :with_file) }
let(:builder) { ActionView::Helpers::FormBuilder.new(:gallery_asset, asset, view, {}) }

before do
render partial: "shared/form_image_field", locals: { f: builder, label: "Gallery 1" }
end

it "links the attached file's name so it opens in a new tab" do
expect(rendered).to have_css("a[href][target='_blank'][rel='noopener']", text: asset.file.filename.to_s)
end
Comment on lines +11 to +13
end