Skip to content

Commit

Permalink
Fix classes on character count when in error state
Browse files Browse the repository at this point in the history
The template correctly adds whitespace between classnames when either the `—error` modifier is added or when custom classes are added, but not when both are added.

This means for example that if you were passing the custom class `app-character-count--custom-modifier` to the character count component whilst it was in an error state, the resulting class attribute would be `govuk-js-character-count govuk-textarea--errorapp-character-count--custom-modifier` – neither the error styling nor the custom class would be correctly applied.

Fixes #1630
  • Loading branch information
36degrees committed Nov 6, 2019
1 parent 326a9e6 commit 58cc438
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/govuk/components/character-count/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
rows: params.rows,
value: params.value,
formGroup: params.formGroup,
classes: 'govuk-js-character-count ' + (' govuk-textarea--error' if params.errorMessage) + (params.classes if params.classes),
classes: 'govuk-js-character-count' + (' govuk-textarea--error' if params.errorMessage) + (' ' + params.classes if params.classes),
label: {
html: params.label.html,
text: params.label.text,
Expand Down
12 changes: 12 additions & 0 deletions src/govuk/components/character-count/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ describe('Character count', () => {
const $component = $('.govuk-js-character-count')
expect($component.hasClass('govuk-textarea--error')).toBeTruthy()
})

it('renders with classes', () => {
const $ = render('character-count', {
errorMessage: {
text: 'Error message'
},
classes: 'app-character-count--custom-modifier'
})

const $component = $('.govuk-js-character-count')
expect($component.hasClass('app-character-count--custom-modifier')).toBeTruthy()
})
})

describe('with dependant components', () => {
Expand Down

0 comments on commit 58cc438

Please sign in to comment.