Skip to content

Commit

Permalink
Ensure that invisible character count message is hidden to all users
Browse files Browse the repository at this point in the history
We use `visibility` to ensure the character count keeps the same size in the page, but this requires additional work to ensure it's not visible to an assistive technology like a screen reader.
  • Loading branch information
NickColley committed Jun 12, 2019
1 parent 880ff50 commit f1ff89a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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 f1ff89a

Please sign in to comment.