-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix (16747)(A11y) : Proper Conveyance of Word/Character Count by screen readers #16898
Fix (16747)(A11y) : Proper Conveyance of Word/Character Count by screen readers #16898
Conversation
✅ Deploy Preview for v11-carbon-react ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for carbon-elements ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, but one small optimization we could make
setTimeout( | ||
() => { | ||
if (announcer) { | ||
announcer.textContent = ariaAnnouncement; | ||
setPrevAnnouncement(ariaAnnouncement); | ||
} | ||
}, | ||
counterMode === 'word' ? 2000 : 1000 | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be best to be sure the timeout is cleared in the useEffect cleanup just in case the component unmounts before the timeout expires. In theory this should be garbage collected but it's a small add for this extra assurance.
// Clear the content first | ||
announcer.textContent = ''; | ||
// Set the new content after a small delay | ||
setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here with clearing this timeout just in case
bf33904
Closes #16747
When the
maxCount
word limit is set along with theenableCounter
prop, the screen reader announcement for the word/character count used to only triggers once when10 words/characters
were left.Also, no announcements are made when the
maximum
word/character count is reached. This inconsistency makes it difficult for screen reader users to understand the remaining count and when the limit is hit.This PR does two things
Incremental Announcements
It will now make announcements for each of the last 10 characters/words, properly conveying the remaining count.
Max Count Announcement
An additional announcement will be made when the maximum word/character count is reached, ensuring users are informed when the limit is hit.
Changelog
The
useAnnouncer
function is updated to track when the maximum limit is reached and ensure announcements are made for each of the last 10 characters/words.The test cases for
useAnnouncer
have been updated to reflect the new changes and ensure proper functionality.Within the component, useAnnouncer is called inside a
useEffect
hook to manage the timing of announcements.This is to ensures that same announcements are not repeated unnecessarily and are made after a delay, allowing both the counter and the announcement of the actual text being written to be audible
Testing / Reviewing
Also verify that readOnly status is announced by screenReader when readonly is true