-
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
Merged
riddhybansal
merged 13 commits into
carbon-design-system:main
from
2nikhiltom:fix_16747_jaws
Jul 23, 2024
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
041693e
fix(15337): fix release names in update automation
2nikhiltom 275eb71
fix(15337): fix release names in update automation
2nikhiltom 6def269
Merge branch 'carbon-design-system:main' into main
2nikhiltom ff5082b
Merge branch 'carbon-design-system:main' into main
2nikhiltom ee20e94
Merge branch 'main' of https://github.com/2nikhiltom/carbon
2nikhiltom ff9af1e
fix(16747): updates useAnnouncer, and text compo for a11y
2nikhiltom 804a51c
chore: removed comment and spaces
2nikhiltom cdad52e
fix: readonly status
2nikhiltom aa63798
Merge branch 'main' into fix_16747_jaws
2nikhiltom c6e7426
Merge branch 'main' into fix_16747_jaws
2nikhiltom cdefdbc
chore: removed conflict
2nikhiltom 126ee89
fix: adds cleanup for timeouts
2nikhiltom 89343d7
Merge branch 'main' into fix_16747_jaws
riddhybansal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,13 @@ | |
*/ | ||
|
||
import PropTypes from 'prop-types'; | ||
import React, { ReactNode, useContext, useState } from 'react'; | ||
import React, { | ||
ReactNode, | ||
useContext, | ||
useState, | ||
useEffect, | ||
useRef, | ||
} from 'react'; | ||
import classNames from 'classnames'; | ||
import { useNormalizedInputProps } from '../../internal/useNormalizedInputProps'; | ||
import PasswordInput from './PasswordInput'; | ||
|
@@ -310,7 +316,25 @@ const TextInput = React.forwardRef(function TextInput( | |
); | ||
|
||
const { isFluid } = useContext(FormContext); | ||
const announcerRef = useRef(null); | ||
const [prevAnnouncement, setPrevAnnouncement] = useState(''); | ||
const ariaAnnouncement = useAnnouncer(textCount, maxCount); | ||
useEffect(() => { | ||
if (ariaAnnouncement && ariaAnnouncement !== prevAnnouncement) { | ||
const announcer = announcerRef.current as HTMLSpanElement | null; | ||
if (announcer) { | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here with clearing this timeout just in case |
||
if (announcer) { | ||
announcer.textContent = ariaAnnouncement; | ||
setPrevAnnouncement(ariaAnnouncement); | ||
} | ||
}, 1000); | ||
} | ||
} | ||
}, [ariaAnnouncement, prevAnnouncement]); | ||
const Icon = normalizedProps.icon as any; | ||
|
||
// Slug is always size `mini` | ||
|
@@ -338,7 +362,12 @@ const TextInput = React.forwardRef(function TextInput( | |
{Icon && <Icon className={iconClasses} />} | ||
{input} | ||
{normalizedSlug} | ||
<span className={`${prefix}--text-input__counter-alert`} role="alert"> | ||
<span | ||
className={`${prefix}--text-input__counter-alert`} | ||
role="alert" | ||
aria-live="assertive" | ||
aria-atomic="true" | ||
ref={announcerRef}> | ||
{ariaAnnouncement} | ||
</span> | ||
{isFluid && <hr className={`${prefix}--text-input__divider`} />} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.