Skip to content

Commit

Permalink
Add missing spellcheck param to character count
Browse files Browse the repository at this point in the history
We added a new spellcheck param to the textarea component in #1859

However, we forgot to add the param to the character count component, which meant it couldn't be passed through to the textarea. This adds the missing param.
  • Loading branch information
Vanita Barrett committed Jul 17, 2020
1 parent ce8e223 commit 04f5313
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/govuk/components/character-count/character-count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const configPaths = require('../../../../config/paths.json')
const PORT = configPaths.ports.test
const baseUrl = `http://localhost:${PORT}`

const { render } = require('../../../../lib/jest-helpers')

const goToExample = (exampleName = false) => {
const url = exampleName
? `${baseUrl}/components/character-count/${exampleName}/preview`
Expand Down Expand Up @@ -143,6 +145,36 @@ describe('Character count', () => {
})
})

describe('when it has the spellcheck attribute', () => {
it('renders with spellcheck attribute set to true', () => {
const $ = render('character-count', {
spellcheck: true
})

const $component = $('.govuk-character-count .govuk-textarea')
expect($component.attr('spellcheck')).toEqual('true')
})

it('renders with spellcheck attribute set to false', () => {
const $ = render('character-count', {
name: 'my-char-count-name',
spellcheck: false
})

const $component = $('.govuk-character-count .govuk-textarea')
expect($component.attr('spellcheck')).toEqual('false')
})

it('renders without spellcheck attribute by default', () => {
const $ = render('character-count', {
name: 'my-char-count-name'
})

const $component = $('.govuk-character-count .govuk-textarea')
expect($component.attr('spellcheck')).toBeUndefined()
})
})

describe('when counting words', () => {
it('shows the dynamic message', async () => {
await goToExample('with-word-count')
Expand Down
4 changes: 4 additions & 0 deletions src/govuk/components/character-count/character-count.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ params:
type: object
required: false
description: HTML attributes (for example data attributes) to add to the textarea.
- name: spellcheck
type: boolean
required: false
description: Optional field to enable or disable the spellcheck attribute on the character count.
- name: countMessage
type: object
required: false
Expand Down
1 change: 1 addition & 0 deletions src/govuk/components/character-count/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
name: params.name,
describedBy: params.id + '-info',
rows: params.rows,
spellcheck: params.spellcheck,
value: params.value,
formGroup: params.formGroup,
classes: 'govuk-js-character-count' + (' govuk-textarea--error' if params.errorMessage) + (' ' + params.classes if params.classes),
Expand Down

0 comments on commit 04f5313

Please sign in to comment.