Skip to content

Commit

Permalink
add "(opens in new tab)" suffix to links
Browse files Browse the repository at this point in the history
Links should have `(opens in new tab)` suffix so that users can expect the link to open in a new tab.

see https://design-system.service.gov.uk/styles/links/#external-links
  • Loading branch information
aliuk2012 committed Dec 18, 2023
1 parent ef476d0 commit ba363ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/govuk-forms-markdown/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def triple_emphasis(text)

def link(link, title, content)
title_attribute = title.nil? ? "" : " title=\"#{title}\""
%(<a href="#{link}" class="govuk-link"#{title_attribute} rel="noreferrer noopener" target="_blank">#{content}</a>)
%(<a href="#{link}" class="govuk-link"#{title_attribute} rel="noreferrer noopener" target="_blank">#{content} (opens in new tab)</a>)
end

def list(contents, list_type)
Expand Down
4 changes: 2 additions & 2 deletions spec/govuk-forms-markdown/renderer/link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

context "when there is no title" do
it "renders a link" do
expect(renderer.link("https://example.com", nil, "Link content").strip).to eq "<a href=\"https://example.com\" class=\"govuk-link\" rel=\"noreferrer noopener\" target=\"_blank\">Link content</a>"
expect(renderer.link("https://example.com", nil, "Link content").strip).to eq "<a href=\"https://example.com\" class=\"govuk-link\" rel=\"noreferrer noopener\" target=\"_blank\">Link content (opens in new tab)</a>"
end
end

context "when there is a title" do
it "renders a link" do
expect(renderer.link("https://example.com", "Link title", "Link content").strip).to eq "<a href=\"https://example.com\" class=\"govuk-link\" title=\"Link title\" rel=\"noreferrer noopener\" target=\"_blank\">Link content</a>"
expect(renderer.link("https://example.com", "Link title", "Link content").strip).to eq "<a href=\"https://example.com\" class=\"govuk-link\" title=\"Link title\" rel=\"noreferrer noopener\" target=\"_blank\">Link content (opens in new tab)</a>"
end
end
end
Expand Down

0 comments on commit ba363ac

Please # to comment.