Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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