Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support opening url in a new browser tab #2134

Closed
shouichi opened this issue Jan 27, 2022 · 1 comment · Fixed by #2139
Closed

Support opening url in a new browser tab #2134

shouichi opened this issue Jan 27, 2022 · 1 comment · Fixed by #2139

Comments

@shouichi
Copy link
Contributor

  • What would you like to be able to do? Can you provide some examples?

By using Field::Url we can display URLs as links. In some cases, it would be convenient to open links in new browser tabs.

  • How could we go about implementing that?

Though the implementation would be straightforward, we may want to add rel="noopener" or rel="noreferrer.

https://docs.rubocop.org/rubocop-rails/cops_rails.html#railslinktoblank

  • Can you think of other approaches to the problem?

No.

@nickcharlton
Copy link
Member

It's not something we currently support. I wondered if we'd exposed enough of the HTML options to do it, but apparently not. content_tag accepts a hash of options, so you could do similar things too. It'd be nice to be able to do this on all fields, I'd think, if you or someone was able to open a PR to do so.

You could do something like this, but it'd mean overriding the partials in your project:

# dashboard
ATTRIBUTE_TYPES = {
  image_url: Field::Url.with_options(target: "_blank"),
}
# field partial
<%= content_tag :a, href: field.data, target: field.options[:target] do %>
  <%= field.data %>
<% end %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants