Skip to content

Commit

Permalink
Fix missing class on form group when govukInput has an error (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
stdstaff committed Oct 12, 2022
1 parent 9f34e5e commit 5490201
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
24 changes: 12 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
govuk-design-system-rails (0.9.4)
govuk-design-system-rails (0.9.5)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -131,7 +131,7 @@ GEM
thor (~> 1.0)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.5.0)
regexp_parser (2.6.0)
rexml (3.2.5)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
Expand All @@ -141,14 +141,14 @@ GEM
rspec-mocks (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-rails (5.1.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
rspec-core (~> 3.10)
rspec-expectations (~> 3.10)
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-rails (6.0.0)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.11)
rspec-expectations (~> 3.11)
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-support (3.11.1)
rubocop (1.35.0)
json (~> 2.3)
Expand Down Expand Up @@ -187,7 +187,7 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.5.0)
sqlite3 (1.5.3)
mini_portile2 (~> 2.8.0)
super_diff (0.9.0)
attr_extras (>= 6.2.4)
Expand All @@ -200,7 +200,7 @@ GEM
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.0)
zeitwerk (2.6.1)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion app/views/components/_govuk_input.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% described_by = local_assigns[:describedBy] %>
<% form_group_classes = class_names(
'govuk-form-group',
{ 'govuk-form-group--error' => local_assigns.dig(:formGroup, :errorMessage) },
{ 'govuk-form-group--error' => local_assigns[:errorMessage] },
local_assigns.dig(:formGroup, :classes)
)
%>
Expand Down
2 changes: 1 addition & 1 deletion govuk_design_system-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $LOAD_PATH.push File.expand_path("lib", __dir__)

Gem::Specification.new do |s|
s.name = "govuk-design-system-rails"
s.version = "0.9.4"
s.version = "0.9.5"
s.authors = %w[OfficeForProductSafetyAndStandards]
s.summary = "An implementation of the govuk-frontend macros in Ruby on Rails"
s.test_files = Dir["spec/**/*"]
Expand Down
40 changes: 40 additions & 0 deletions spec/helpers/govuk_design_system/input_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,45 @@
</div>
HTML
end

it "handles error messages correctly" do
html = helper.govukInput({
id: "cost-per-item-error",
name: "cost-per-item-error",
label: {
text: "What is the cost per item, in pounds?",
classes: "govuk-label--l",
isPageHeading: true
},
prefix: {
text: "£"
},
suffix: {
text: "per item"
},
errorMessage: {
text: "Enter a cost per item, in pounds"
},
classes: "govuk-input--width-5",
spellcheck: false
})

expect(html).to match_html(<<~HTML)
<div class="govuk-form-group govuk-form-group--error">
<h1 class="govuk-label-wrapper"><label class="govuk-label govuk-label--l" for="cost-per-item-error">
What is the cost per item, in pounds?
</label>
</h1>
<p id="cost-per-item-error-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> Enter a cost per item, in pounds
</p>
<div class="govuk-input__wrapper">
<div class="govuk-input__prefix" aria-hidden="true">£</div>
<input class="govuk-input govuk-input--width-5 govuk-input--error" id="cost-per-item-error" name="cost-per-item-error" type="text" spellcheck="false" aria-describedby="cost-per-item-error-error">
<div class="govuk-input__suffix" aria-hidden="true">per item</div>
</div>
</div>
HTML
end
end
end

0 comments on commit 5490201

Please sign in to comment.