Skip to content

Commit

Permalink
Merge pull request #2590 from andymantell/fix/character-count-maxlength
Browse files Browse the repository at this point in the history
Maxlength attribute should not be present on textarea after character-count JavaScript has kicked in
  • Loading branch information
Vanita Barrett-Smith authored Apr 20, 2022
2 parents 95c4209 + 2ec4c14 commit cea3233
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ We’ve also made fixes in the following pull requests:

- [#2549: Fix header with product name focus and hover state length](https://github.com/alphagov/govuk-frontend/pull/2549)
- [#2573: Better handle cases where `$govuk-text-colour` is set to a non-colour value](https://github.com/alphagov/govuk-frontend/pull/2573)
- [#2590: Maxlength attribute should not be present on textarea after character-count JavaScript has kicked in](https://github.com/alphagov/govuk-frontend/pull/2590)

## 4.0.1 (Fix release)

Expand Down
2 changes: 1 addition & 1 deletion src/govuk/components/character-count/character-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ CharacterCount.prototype.init = function () {
}

// Remove hard limit if set
$module.removeAttribute('maxlength')
$textarea.removeAttribute('maxlength')

this.bindChangeEvents()

Expand Down
11 changes: 11 additions & 0 deletions src/govuk/components/character-count/character-count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ describe('Character count', () => {
expect(srMessage).toEqual('You have 10 characters remaining')
})
})

describe('when a maxlength attribute is specified on the textarea', () => {
beforeAll(async () => {
await goToExample('with-textarea-maxlength-attribute')
})

it('should not have a maxlength attribute once the JS has run', async () => {
const textareaMaxLength = await page.$eval('.govuk-textarea', el => el.getAttribute('maxlength'))
expect(textareaMaxLength).toBeNull()
})
})
})

describe('when counting words', () => {
Expand Down
10 changes: 10 additions & 0 deletions src/govuk/components/character-count/character-count.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,13 @@ examples:
maxlength: 10
label:
text: Full address
- name: with textarea maxlength attribute
hidden: true
data:
id: maxlength-should-be-removed
name: address
maxlength: 10
attributes:
maxlength: 10
label:
text: Full address

0 comments on commit cea3233

Please sign in to comment.