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

Allow inset-text to take a block #1078

Merged
merged 2 commits into from
Sep 4, 2019
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Remove govuk_frontend_toolkit sass dependencies (PR #1069)
* Explicitly set focus states (PR #1071)
* Override edit link text on summary-link component (#1076)
* Allow inset-text to take a block (PR #1078)

## 18.3.1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<%
id ||= "inset-text-#{SecureRandom.hex(4)}"
%>

<%= tag.div id: id, class: "gem-c-inset-text govuk-inset-text" do %>
<%= text %>
<% if defined? text %>
<%= text %>
<% elsif block_given? %>
<%= yield %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ examples:
default:
data:
text: "It can take up to 8 weeks to register a lasting power of attorney if there are no mistakes in the application."

with_block:
description: |
Note that the contents should be styled separately from the component, which takes no responsibility for what it is passed.
data:
block: |
<div>
<h2 id='heading'>To publish this step by step you need to</h2>
<a href='/foo'>Check for broken links</a>
</div>
19 changes: 19 additions & 0 deletions spec/components/inset_text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,23 @@ def component_name

assert_select(".govuk-inset-text", text: "It can take up to 8 weeks to register a lasting power of attorney if there are no mistakes in the application.")
end

it "renders a block" do
block = "
<h2 id='heading'>To publish this step by step you need to</h2>
<a href='/foo'>Check for broken links</a>
".html_safe
render_component({}) { block }

assert_select(".govuk-inset-text h2#heading", text: "To publish this step by step you need to")
assert_select(".govuk-inset-text a[href='/foo']", text: "Check for broken links")
end

it "renders only the text if both text and block are provided" do
block = "<p id='foo'>Foo</p>".html_safe
render_component(text: 'Bar') { block }

assert_select(".govuk-inset-text", text: "Bar")
assert_select(".govuk-inset-text p#foo", false, "Block should not have rendered")
end
end