Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
7e4d751f
Commit
7e4d751f
authored
Sep 06, 2022
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Sep 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add screen-reader announcements of AdderToolbar keyboard shortcuts
parent
0211926f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
2 deletions
+110
-2
AdderToolbar.tsx
src/annotator/components/AdderToolbar.tsx
+44
-0
AdderToolbar-test.js
src/annotator/components/test/AdderToolbar-test.js
+66
-2
No files found.
src/annotator/components/AdderToolbar.tsx
View file @
7e4d751f
...
...
@@ -101,6 +101,46 @@ function ToolbarButton({
);
}
/**
* Render non-visible content for screen readers to announce adder keyboard
* shortcuts and count of annotations associated with the current selection.
*/
function
AdderToolbarShortcuts
({
annotationCount
,
isVisible
,
}:
{
annotationCount
:
number
;
isVisible
:
boolean
;
})
{
return
(
<
div
className=
"sr-only"
>
<
span
aria
-
live=
"polite"
aria
-
atomic=
"true"
role=
"status"
data
-
testid=
"annotation-count-announce"
>
{
annotationCount
>
0
&&
(
<
span
>
{
annotationCount
}{
' '
}
{
annotationCount
===
1
?
'annotation'
:
'annotations'
}
for this
selection.
</
span
>
)
}
</
span
>
<
ul
aria
-
live=
"polite"
data
-
testid=
"annotate-shortcuts-announce"
>
{
isVisible
&&
(
<>
{
annotationCount
>
0
&&
<
li
>
Press
{
"'S'"
}
to show annotations.
</
li
>
}
<
li
>
Press
{
"'A'"
}
to annotate.
</
li
>
<
li
>
Press
{
"'H'"
}
to highlight.
</
li
>
</>
)
}
</
ul
>
</
div
>
);
}
export
type
Command
=
'annotate'
|
'highlight'
|
'show'
|
'hide'
;
type
AdderToolbarProps
=
{
...
...
@@ -240,6 +280,10 @@ export default function AdderToolbar({
)
}
</
div
>
<
AdderToolbarArrow
arrowDirection=
{
arrowDirection
}
/>
<
AdderToolbarShortcuts
annotationCount=
{
annotationCount
}
isVisible=
{
isVisible
}
/>
</
div
>
);
}
src/annotator/components/test/AdderToolbar-test.js
View file @
7e4d751f
import
{
mount
}
from
'enzyme'
;
import
AdderToolbar
from
'../AdderToolbar'
;
// nb. Most tests for `AdderToolbar` are currently covered by `adder-test.js`.
// This needs refactoring to test the `AdderToolbar` on its own as a unit.
describe
(
'AdderToolbar'
,
()
=>
{
// nb. Most tests for `AdderToolbar` are currently covered by `adder-test.js`.
// This needs refactoring to test the `AdderToolbar` on its own as a unit.
const
createComponent
=
props
=>
mount
(
<
AdderToolbar
direction
=
"up"
annotationCount
=
{
0
}
onCommand
=
{()
=>
{}}
isVisible
=
{
true
}
{...
props
}
/
>
);
describe
(
'keyboard shortcut content for screen readers'
,
()
=>
{
it
(
'renders keyboard shortcuts for annotate and highlight actions'
,
()
=>
{
const
wrapper
=
createComponent
();
const
shortcutListItems
=
wrapper
.
find
(
'[data-testid="annotate-shortcuts-announce"]'
)
.
find
(
'li'
);
assert
.
equal
(
shortcutListItems
.
length
,
2
);
assert
.
include
(
shortcutListItems
.
at
(
0
).
text
(),
'annotate'
);
assert
.
include
(
shortcutListItems
.
at
(
1
).
text
(),
'highlight'
);
});
it
(
'does not render keyboard shortcut items if adder is not visible'
,
()
=>
{
const
wrapper
=
createComponent
({
isVisible
:
false
});
const
shortcutListItems
=
wrapper
.
find
(
'[data-testid="annotate-shortcuts-announce"]'
)
.
find
(
'li'
);
assert
.
equal
(
shortcutListItems
.
length
,
0
);
});
it
(
'renders a keyboard shortcut to show annotations when there are annotations to show'
,
()
=>
{
const
wrapper
=
createComponent
({
annotationCount
:
2
});
const
shortcutListItems
=
wrapper
.
find
(
'[data-testid="annotate-shortcuts-announce"]'
)
.
find
(
'li'
);
assert
.
equal
(
shortcutListItems
.
length
,
3
);
assert
.
include
(
shortcutListItems
.
at
(
0
).
text
(),
'show annotations'
);
});
it
(
'renders status information about annotation count when there are annotations to show'
,
()
=>
{
const
wrapper
=
createComponent
({
annotationCount
:
2
});
const
annotationCountStatus
=
wrapper
.
find
(
'[data-testid="annotation-count-announce"]'
);
assert
.
include
(
annotationCountStatus
.
text
(),
'2 annotations'
);
});
it
(
'does not render status information about annotation count when there are no annotations'
,
()
=>
{
const
wrapper
=
createComponent
({
annotationCount
:
0
});
const
annotationCountStatus
=
wrapper
.
find
(
'[data-testid="annotation-count-announce"]'
);
assert
.
isEmpty
(
annotationCountStatus
.
text
());
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment