-
Notifications
You must be signed in to change notification settings - Fork 18
fix(a11y): announce dynamic status and errors via live regions (A11Y-… #3005
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
Open
sunilsabatp
wants to merge
3
commits into
develop
Choose a base branch
from
fix/a11y-010-status-messages
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
dc8ca58
fix(a11y): announce dynamic status and errors via live regions (A11Y-…
sunilsabatp a934773
fix(a11y): keep polite live regions mounted so updates are announced …
sunilsabatp 1ae6274
docs(a11y): mark A11Y-010 complete and track empty-state alt text as …
sunilsabatp 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
58 changes: 38 additions & 20 deletions
58
src/features/common/ContentLoaders/Projects/GlobeLoader.tsx
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Screen-reader-only content: removed from the visual flow so it reserves no | ||
| // space, while remaining announced by assistive tech. | ||
| // `display: none` / `visibility: hidden` would remove it from the a11y tree, | ||
| // so the clip technique is used instead. | ||
| .visuallyHidden { | ||
| position: absolute; | ||
| width: 1px; | ||
| height: 1px; | ||
| padding: 0; | ||
| margin: -1px; | ||
| overflow: hidden; | ||
| clip: rect(0, 0, 0, 0); | ||
| white-space: nowrap; | ||
| border: 0; | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import type { ReactElement, ReactNode } from 'react'; | ||
|
|
||
| import { clsx } from 'clsx'; | ||
| import styles from './LiveRegion.module.scss'; | ||
|
|
||
| /** | ||
| * How urgently an update should reach a screen reader. | ||
| * | ||
| * - `assertive` → `role="alert"`. Interrupts whatever is being read. Use for | ||
| * errors and failed actions the user must hear right away. | ||
| * - `polite` → `role="status"`. Queued until the reader is idle. Use for | ||
| * result counts, empty states, upload/save progress and success messages. | ||
| */ | ||
| export type LiveRegionPoliteness = 'assertive' | 'polite'; | ||
|
|
||
| /** Elements a live region may render as. Kept to text-level containers. */ | ||
| export type LiveRegionElement = 'div' | 'p' | 'span'; | ||
|
|
||
| export interface LiveRegionProps { | ||
| /** Announcement urgency. Maps to `role="alert"` / `role="status"`. */ | ||
| politeness: LiveRegionPoliteness; | ||
|
|
||
| /** The message. May be empty while there is nothing to announce. */ | ||
| children?: ReactNode; | ||
|
|
||
| /** Element to render. Defaults to `div`. */ | ||
| as?: LiveRegionElement; | ||
|
|
||
| /** Additional CSS classes. Existing message styling is preserved. */ | ||
| className?: string; | ||
|
|
||
| /** | ||
| * Announce the message without showing it. Use when the visual cue is a | ||
| * spinner or skeleton that carries no text. | ||
| */ | ||
| isVisuallyHidden?: boolean; | ||
|
|
||
| /** Forwarded so the region can still be referenced by `aria-describedby`. */ | ||
| id?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Announces messages that appear or change after the page loads. | ||
| * | ||
| * Screen readers don't automatically read updates in a normal element. | ||
| * Wrapping the content in a live region makes those updates get announced | ||
| * without moving the user's focus. | ||
| * | ||
| * Keep the live region on the page and only update its content instead of | ||
| * adding a new one. This is more reliable for screen readers. | ||
| * | ||
| * This is especially important for `polite` messages. Some screen readers only | ||
| * announce changes inside a live region that is already on the page, so adding | ||
| * the region together with its message may not be announced. `assertive` | ||
| * (`role="alert"`) messages are usually announced even when the region is | ||
| * added with the message. | ||
| * | ||
| * If keeping a visible live region on the page would affect the layout, keep a | ||
| * hidden live region (`isVisuallyHidden`) on the page and render the visible | ||
| * message separately: | ||
| * | ||
| * ```tsx | ||
| * <LiveRegion politeness="polite" isVisuallyHidden> | ||
| * {isSaving ? t('saving') : ''} | ||
| * </LiveRegion> | ||
| * {isSaving && <div className={styles.spinner} />} | ||
| * ``` | ||
| * | ||
| * Don't place a live region inside an element with `aria-busy={true}`. | ||
| * Screen readers wait until the busy element has finished updating, so | ||
| * messages inside it may not be announced. Render the live region next to the | ||
| * busy element instead. | ||
| */ | ||
| function LiveRegion({ | ||
| politeness, | ||
| children, | ||
| as: Element = 'div', | ||
| className, | ||
| isVisuallyHidden = false, | ||
| id, | ||
| }: LiveRegionProps): ReactElement { | ||
| return ( | ||
| <Element | ||
| id={id} | ||
| role={politeness === 'assertive' ? 'alert' : 'status'} | ||
| // Both roles already imply these values, but some older | ||
| // screen-reader/browser pairs only act on the explicit attributes. | ||
| aria-live={politeness} | ||
| aria-atomic="true" | ||
| className={clsx(isVisuallyHidden && styles.visuallyHidden, className)} | ||
| > | ||
| {children} | ||
| </Element> | ||
| ); | ||
| } | ||
|
|
||
| export default LiveRegion; |
This file contains hidden or 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.
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Plant-for-the-Planet-org/planet-webapp
Length of output: 8253
Replace deprecated
clipwithclip-path.clip: rect(...)is legacy CSS; for this visually hidden pattern, useclip-path: inset(50%)so the project stops relying on deprecated CSS when browser support is already modern enough for the rest of the codebase.🧰 Tools
🪛 Stylelint (17.14.0)
[error] 12-12: Deprecated property "clip" (property-no-deprecated)
(property-no-deprecated)
🤖 Prompt for AI Agents
Source: Linters/SAST tools