-
-
Notifications
You must be signed in to change notification settings - Fork 613
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 page changes not being announced by assistive technology when navigating using the client-side router #5288
Open
JeffersonBledsoe
wants to merge
19
commits into
main
Choose a base branch
from
screenreader-page-change
base: main
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 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
317d5d7
WIP: title change announcements using MutationObserver
JeffersonBledsoe e491253
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe 959bf1a
Move to packages location
JeffersonBledsoe a2dd1da
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe 86d5b6b
Listen for back and forward events and handle those the same way
JeffersonBledsoe 61322e6
Merge branch 'main' into screenreader-page-change
ichim-david 656312e
Changelog
JeffersonBledsoe c92a260
Update snapshot
JeffersonBledsoe ff5b4dc
Remove comment
JeffersonBledsoe 2a5cd4c
Fix test failure
JeffersonBledsoe 76ea106
Test fixes
JeffersonBledsoe 5f76479
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe 76a99c0
Fix unwanted test change
JeffersonBledsoe dd95864
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe 7bacf17
Remove initial "Route content change" contents incase a user somehow …
JeffersonBledsoe 3acd44b
Move updatePage inside the useEffect
JeffersonBledsoe 2455cf8
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe 123c9d1
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe f284734
Merge branch 'main' into screenreader-page-change
ichim-david 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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed page changes not being announced to screen reader users. @JeffersonBledsoe |
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
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
65 changes: 65 additions & 0 deletions
65
packages/volto/src/components/theme/RouteAnnouncer/RouteAnnouncer.jsx
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
function RouteAnnouncer() { | ||
const [pageTitle, setPageTitle] = useState('Route content change'); | ||
|
||
function updatePage(title) { | ||
setPageTitle(title); | ||
document.activeElement.blur(); | ||
} | ||
|
||
useEffect(() => { | ||
function handlePop(event) { | ||
const pageTitle = event.target.document.title; | ||
updatePage(pageTitle); | ||
} | ||
|
||
const observer = new MutationObserver((mutationList) => { | ||
for (const mutation of mutationList) { | ||
if (mutation.type === 'childList') { | ||
for (const node of mutation.addedNodes) { | ||
if (node.nodeType === Node.TEXT_NODE && node.textContent) { | ||
updatePage(node.textContent); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
observer.observe(document.querySelector('title'), { | ||
characterData: true, | ||
attributes: true, | ||
childList: true, | ||
subtree: true, | ||
}); | ||
window.addEventListener('popstate', handlePop); | ||
|
||
return () => { | ||
observer.disconnect(); | ||
window.removeEventListener('popstate', handlePop); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<p | ||
id="route-announcer" | ||
role="alert" | ||
// Off-screen element with 'best' browser support | ||
style={{ | ||
border: 0, | ||
clip: 'rect(1px 1px 1px 1px)', // IE-style CSS for compatibility | ||
height: '1px', | ||
margin: '-1px', | ||
overflow: 'hidden', | ||
padding: 0, | ||
position: 'absolute', | ||
width: '1px', | ||
whiteSpace: 'nowrap', | ||
wordWrap: 'normal', | ||
}} | ||
> | ||
{pageTitle} | ||
</p> | ||
); | ||
} | ||
|
||
export default RouteAnnouncer; |
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.
By just looking at the code I would say that eslint should complain that this array should at least contain the
updatePage
function. Would it be possible to move it inside theuseEffect
next tohandlePop
?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.
@pnicolli The linters don't seem to complain, but I've moved it within regardless