Skip to content

Commit

Permalink
Merge pull request #1442 from alphagov/ensure-character-count-message…
Browse files Browse the repository at this point in the history
…-is-hidden-when-not-visible

Ensure character count message is hidden to assistive technologies when not visible
  • Loading branch information
NickColley authored Jun 12, 2019
2 parents 880ff50 + 6bc9986 commit 5c70e71
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@

([PR #1441](https://github.com/alphagov/govuk-frontend/pull/1441))

- Ensure character count message is hidden to assistive technologies when not visible

([PR #1442](https://github.com/alphagov/govuk-frontend/pull/1442))

- Stop appending hash when error summary link clicked

This prevents incorrectly focusing the form element with the hash id, instead of the error summary, when form is re-submitted with the hash in the URL and there are further errors.
Expand Down
4 changes: 4 additions & 0 deletions src/components/character-count/character-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,12 @@ CharacterCount.prototype.updateCountMessage = function () {
var thresholdValue = maxLength * thresholdPercent / 100
if (thresholdValue > currentLength) {
countMessage.classList.add('govuk-character-count__message--disabled')
// Ensure threshold is hidden for users of assistive technologies
countMessage.setAttribute('aria-hidden', true)
} else {
countMessage.classList.remove('govuk-character-count__message--disabled')
// Ensure threshold is visible for users of assistive technologies
countMessage.removeAttribute('aria-hidden')
}

// Update styles
Expand Down
8 changes: 8 additions & 0 deletions src/components/character-count/character-count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,21 @@ describe('Character count', () => {
it('does not show the limit until the threshold is reached', async () => {
const visibility = await page.$eval('.govuk-character-count__message', el => window.getComputedStyle(el).visibility)
expect(visibility).toEqual('hidden')

// Ensure threshold is hidden for users of assistive technologies
const ariaHidden = await page.$eval('.govuk-character-count__message', el => el.getAttribute('aria-hidden'))
expect(ariaHidden).toEqual('true')
})

it('becomes visible once the threshold is reached', async () => {
await page.type('.js-character-count', 'A'.repeat(8))

const visibility = await page.$eval('.govuk-character-count__message', el => window.getComputedStyle(el).visibility)
expect(visibility).toEqual('visible')

// Ensure threshold is visible for users of assistive technologies
const ariaHidden = await page.$eval('.govuk-character-count__message', el => el.getAttribute('aria-hidden'))
expect(ariaHidden).toBeFalsy()
})
})
})
Expand Down

0 comments on commit 5c70e71

Please sign in to comment.