-
-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix page changes not being announced by assistive technology when nav…
…igating using the client-side router (#5288) Co-authored-by: ichim-david <[email protected]>
- Loading branch information
1 parent
ee3c972
commit e5b8a40
Showing
8 changed files
with
107 additions
and
12 deletions.
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
64 changes: 64 additions & 0 deletions
64
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,64 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
function RouteAnnouncer() { | ||
const [pageTitle, setPageTitle] = useState(''); | ||
|
||
useEffect(() => { | ||
function updatePage(title) { | ||
setPageTitle(title); | ||
document.activeElement.blur(); | ||
} | ||
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; |