Skip to content
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

Merged
merged 21 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
317d5d7
WIP: title change announcements using MutationObserver
JeffersonBledsoe Oct 7, 2023
e491253
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe Jul 2, 2024
959bf1a
Move to packages location
JeffersonBledsoe Jul 2, 2024
a2dd1da
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe Sep 24, 2024
86d5b6b
Listen for back and forward events and handle those the same way
JeffersonBledsoe Sep 24, 2024
61322e6
Merge branch 'main' into screenreader-page-change
ichim-david Sep 25, 2024
656312e
Changelog
JeffersonBledsoe Sep 26, 2024
c92a260
Update snapshot
JeffersonBledsoe Sep 26, 2024
ff5b4dc
Remove comment
JeffersonBledsoe Sep 26, 2024
2a5cd4c
Fix test failure
JeffersonBledsoe Sep 26, 2024
76ea106
Test fixes
JeffersonBledsoe Sep 26, 2024
5f76479
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe Sep 26, 2024
76a99c0
Fix unwanted test change
JeffersonBledsoe Sep 26, 2024
dd95864
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe Sep 27, 2024
7bacf17
Remove initial "Route content change" contents incase a user somehow …
JeffersonBledsoe Sep 27, 2024
3acd44b
Move updatePage inside the useEffect
JeffersonBledsoe Sep 30, 2024
2455cf8
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe Oct 15, 2024
123c9d1
Merge branch 'main' into screenreader-page-change
JeffersonBledsoe Oct 15, 2024
f284734
Merge branch 'main' into screenreader-page-change
ichim-david Oct 17, 2024
30d3a4f
Merge branch 'main' into screenreader-page-change
ichim-david Oct 29, 2024
49b5d7e
Merge branch 'main' into screenreader-page-change
ichim-david Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/volto/cypress/tests/core/basic/locking.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('Document locking', () => {
cy.visit('/document');
cy.wait('@content');

cy.findByRole('alert')
.get('.toast-inner-content')
cy.get('.Toastify')
.findByRole('alert')
.contains('This item was locked by Editor 1 on');
});

Expand Down
4 changes: 2 additions & 2 deletions packages/volto/cypress/tests/core/basic/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe('Add Content Tests', () => {
cy.get('.ui.basic.icon.button.image').contains('Image').click();
cy.get('#toolbar-save').click();

cy.findByRole('alert')
.get('.toast-inner-content')
cy.get('.Toastify')
.findByRole('alert')
.contains('Required input is missing');
cy.get('.sidebar-container .tabs-wrapper .active.item').contains('Page');
});
Expand Down
19 changes: 14 additions & 5 deletions packages/volto/cypress/tests/workingCopy/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ describe('Working Copy Tests - Create', () => {
it('Basic create operation', function () {
cy.get('#toolbar-more').click();
cy.findByLabelText('Create working copy').click();
cy.findByRole('alert').contains('This is a working copy of');
cy.findByRole('alert')
cy.get('.Toastify')
.findByRole('alert')
.contains('This is a working copy of');
cy.get('.Toastify')
.findByRole('alert')
.get('.toast-inner-content a')
.should('have.attr', 'href')
.and('include', '/document');
Expand All @@ -37,11 +40,17 @@ describe('Working Copy Tests - Create', () => {
it('Navigation through baseline-working copy', function () {
cy.get('#toolbar-more').click();
cy.findByLabelText('Create working copy').click();
cy.findByRole('alert').get('.toast-inner-content a').click();
cy.get('.Toastify')
.findByRole('alert')
.get('.toast-inner-content a')
.click();

cy.url().should('eq', Cypress.config().baseUrl + '/document');
cy.findByRole('alert').contains('This has an ongoing working copy in');
cy.findByRole('alert')
cy.get('.Toastify')
.findByRole('alert')
.contains('This has an ongoing working copy in');
cy.get('.Toastify')
.findByRole('alert')
.get('.toast-inner-content a')
.should('have.attr', 'href')
.and('include', '/working_copy_of_document');
Expand Down
1 change: 1 addition & 0 deletions packages/volto/news/5288.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed page changes not being announced to screen reader users. @JeffersonBledsoe
2 changes: 2 additions & 0 deletions packages/volto/src/components/theme/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import clearSVG from '@plone/volto/icons/clear.svg';
import MultilingualRedirector from '@plone/volto/components/theme/MultilingualRedirector/MultilingualRedirector';
import WorkingCopyToastsFactory from '@plone/volto/components/manage/WorkingCopyToastsFactory/WorkingCopyToastsFactory';
import LockingToastsFactory from '@plone/volto/components/manage/LockingToastsFactory/LockingToastsFactory';
import RouteAnnouncer from '@plone/volto/components/theme/RouteAnnouncer/RouteAnnouncer';

/**
* @export
Expand Down Expand Up @@ -191,6 +192,7 @@ export class App extends Component {
</main>
</Segment>
</MultilingualRedirector>
<RouteAnnouncer />
<Footer />
<LockingToastsFactory
content={this.props.content}
Expand Down
7 changes: 4 additions & 3 deletions packages/volto/src/components/theme/App/App.test.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import config from '@plone/volto/registry';
import React from 'react';
import renderer from 'react-test-renderer';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-intl-redux';
import { MemoryRouter } from 'react-router-dom';
import config from '@plone/volto/registry';
import renderer from 'react-test-renderer';
import configureStore from 'redux-mock-store';

import { __test__ as App } from './App';

Expand Down Expand Up @@ -64,5 +64,6 @@ describe('App', () => {
);
const json = component.toJSON();
expect(json).toMatchSnapshot();
component.unmount();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ Array [
<div
id="segment"
/>,
<p
id="route-announcer"
role="alert"
style={
Object {
"border": 0,
"clip": "rect(1px 1px 1px 1px)",
"height": "1px",
"margin": "-1px",
"overflow": "hidden",
"padding": 0,
"position": "absolute",
"whiteSpace": "nowrap",
"width": "1px",
"wordWrap": "normal",
}
}
/>,
<div
id="footer"
/>,
Expand Down
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);
};
}, []);
JeffersonBledsoe marked this conversation as resolved.
Show resolved Hide resolved

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;
Loading