From 6d411f174335e887ec58c46f2a7ee021720e15fe Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Thu, 5 Sep 2024 00:37:18 -0700 Subject: [PATCH 1/9] miscellaneous a11y improvements - set role="application" on toolbar and sidebar to force screen readers to use focus mode in those areas since reading mode is not applicable here and one should not have to manually switch to focus mode - made outline values visible to screen readers - improved aria-live message announced during search navigation to include the page number as well as the snippet of the result - added role="navigation" to start containers of epub ranges so that screen readers indicate when one moves to a new page. It also enabled navigation via d/shift-d for NVDA and r/shift-r for JAWS to go to next/previous page as with PDFs. - added a state variable a11yVirtualCursorTarget to record which node the screen readers should place its virtual cursor on next time the focus enters the reader. It forces virtual cursor to be moved onto that node, as opposed to landing in the beginning of the document. It is currently used to make sure screen readers begin reading the chapter/section selected in the outline, as well as to place virtual cursor on the last search result. On scroll, a11yVirtualCursorTarget is cleared to not interfere with mouse navigation. To make sure that scroll events of document that fire when outline is navigated don't clear the a11yVirtualCursorTarget that was just set, we wait for scrolling to finish and do not allow a11yVirtualCursorTarget to be cleared if it was added within the last 0.5 second. --- src/common/components/sidebar/outline-view.js | 28 +++--- src/common/components/sidebar/sidebar.js | 4 +- src/common/components/toolbar.js | 2 +- src/common/reader.js | 94 +++++++++++++++---- src/dom/common/dom-view.tsx | 6 ++ src/dom/common/lib/range.ts | 3 + src/dom/epub/epub-view.ts | 48 ++++++++++ src/dom/snapshot/snapshot-view.ts | 34 ++++++- src/pdf/pdf-view.js | 32 +++++++ 9 files changed, 217 insertions(+), 34 deletions(-) diff --git a/src/common/components/sidebar/outline-view.js b/src/common/components/sidebar/outline-view.js index 0e782945..2208d12d 100644 --- a/src/common/components/sidebar/outline-view.js +++ b/src/common/components/sidebar/outline-view.js @@ -43,7 +43,7 @@ function Item({ item, id, children, onOpenLink, onUpdate, onSelect }) { let { expanded, active } = item; return ( -
  • +
  • x.active); let currentItem = list[currentIndex]; @@ -166,6 +166,7 @@ function OutlineView({ outline, onNavigate, onOpenLink, onUpdate}) { ); } + let active = flatten(outline || []).findIndex(item => item.active); return (
    {outline === null ?
    : renderItems(outline)}
    diff --git a/src/common/components/sidebar/sidebar.js b/src/common/components/sidebar/sidebar.js index dfd51e0f..66a533e3 100644 --- a/src/common/components/sidebar/sidebar.js +++ b/src/common/components/sidebar/sidebar.js @@ -19,7 +19,7 @@ function Sidebar(props) { } return ( -
    +
    {props.type === 'pdf' && @@ -72,7 +72,7 @@ function Sidebar(props) {
    {props.annotationsView}
    -
    +
    {props.outlineView}
    diff --git a/src/common/components/toolbar.js b/src/common/components/toolbar.js index d491ddeb..ca1a4ddf 100644 --- a/src/common/components/toolbar.js +++ b/src/common/components/toolbar.js @@ -73,7 +73,7 @@ function Toolbar(props) { } return ( -
    +