Skip to content

Commit

Permalink
Merge pull request #1276 from alphagov/make-character-count-value-req…
Browse files Browse the repository at this point in the history
…uired

Make maxlength or maxwords required
  • Loading branch information
andysellick authored Feb 5, 2020
2 parents b919b35 + 87a191c commit 981c096
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
useful summary for people upgrading their application, not a replication
of the commit log.

## Unreleased

* Make maxlength or maxwords required ([#1276](https://github.com/alphagov/govuk_publishing_components/pull/1276))

## 21.22.0

* Add cookie category lookup function ([#1272](https://github.com/alphagov/govuk_publishing_components/pull/1272))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
threshold ||= nil
textarea ||= {}
%>
<% if maxlength || maxwords %>
<%= content_tag :div,
class: "gem-c-character-count govuk-character-count",
data: {
module: "govuk-character-count",
maxlength: maxlength,
maxwords: maxwords,
threshold: threshold
} do %>

<%= content_tag :div,
class: "gem-c-character-count govuk-character-count",
data: {
module: "govuk-character-count",
maxlength: maxlength,
maxwords: maxwords,
threshold: threshold
} do %>
<%= render "govuk_publishing_components/components/textarea", { id: id, character_count: true }.merge(textarea.symbolize_keys) %>

<%= render "govuk_publishing_components/components/textarea", { id: id, character_count: true }.merge(textarea.symbolize_keys) %>

<span id="<%= id %>-info" class="govuk-hint govuk-character-count__message" aria-live="polite">
You can enter up to <%= maxlength || maxwords %> <%= maxwords ? 'words' : 'characters' %>
</span>
<span id="<%= id %>-info" class="govuk-hint govuk-character-count__message" aria-live="polite">
You can enter up to <%= maxlength || maxwords %> <%= maxwords ? 'words' : 'characters' %>
</span>
<% end %>
<% end %>
8 changes: 6 additions & 2 deletions spec/components/character_count_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def component_name
"character_count"
end

it "fails to render if maxlength or maxwords are not passed" do
assert_empty render_component({})
end

it "renders character count with textarea" do
render_component(
name: "character-count",
Expand All @@ -14,8 +18,8 @@ def component_name
},
data: {
module: "character-count",
maxlength: "100",
}
},
maxlength: "100"
)

assert_select ".govuk-character-count .govuk-textarea"
Expand Down

0 comments on commit 981c096

Please sign in to comment.