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
b3b450c3
Commit
b3b450c3
authored
Jun 13, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jun 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ThreadCard more accessible by allowing focus and adding label for screen readers
parent
c193ceeb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
2 deletions
+43
-2
ThreadCard.tsx
src/sidebar/components/ThreadCard.tsx
+10
-2
ThreadCard-test.js
src/sidebar/components/test/ThreadCard-test.js
+33
-0
No files found.
src/sidebar/components/ThreadCard.tsx
View file @
b3b450c3
...
...
@@ -63,13 +63,14 @@ function ThreadCard({ frameSync, thread }: ThreadCardProps) {
},
[
focusRequest
,
store
,
thread
.
id
]);
return
(
/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */
<
Card
active=
{
isHovered
}
classes=
"cursor-pointer focus-visible-ring theme-clean:border-none"
data
-
testid=
"thread-card"
elementRef=
{
cardRef
}
tabIndex=
{
-
1
}
tabIndex=
{
0
}
role=
"button"
aria
-
label=
"Press Enter to scroll annotation into view"
onClick=
{
e
=>
{
// Prevent click events intended for another action from
// triggering a page scroll.
...
...
@@ -79,6 +80,13 @@ function ThreadCard({ frameSync, thread }: ThreadCardProps) {
}
}
onMouseEnter=
{
()
=>
setThreadHovered
(
thread
.
annotation
??
null
)
}
onMouseLeave=
{
()
=>
setThreadHovered
(
null
)
}
onKeyDown=
{
e
=>
{
// Simulate default button behavior, where `Enter` and `Space` trigger
// click action
if
([
'Enter'
,
' '
].
includes
(
e
.
key
)
&&
thread
.
annotation
)
{
scrollToAnnotation
(
thread
.
annotation
);
}
}
}
key=
{
thread
.
id
}
>
<
CardContent
>
{
threadContent
}
</
CardContent
>
...
...
src/sidebar/components/test/ThreadCard-test.js
View file @
b3b450c3
...
...
@@ -114,6 +114,39 @@ describe('ThreadCard', () => {
});
});
describe
(
'keyboard events'
,
()
=>
{
[
'Enter'
,
' '
].
forEach
(
key
=>
{
it
(
'scrolls to annotation when `Enter` or `Space` are pressed'
,
()
=>
{
const
wrapper
=
createComponent
();
wrapper
.
find
(
threadCardSelector
).
simulate
(
'keydown'
,
{
key
});
assert
.
calledWith
(
fakeFrameSync
.
scrollToAnnotation
,
fakeThread
.
annotation
);
});
it
(
'does not scroll to annotation when it is not set'
,
()
=>
{
const
wrapper
=
createComponent
({
thread
:
{}
});
wrapper
.
find
(
threadCardSelector
).
simulate
(
'keypress'
,
{
key
});
assert
.
notCalled
(
fakeFrameSync
.
scrollToAnnotation
);
});
});
[
'a'
,
'b'
,
'Escape'
,
'ArrowDown'
].
forEach
(
key
=>
{
it
(
'does not scroll to annotation when key other than `Enter` or `Space` is pressed'
,
()
=>
{
const
wrapper
=
createComponent
();
wrapper
.
find
(
threadCardSelector
).
simulate
(
'keypress'
,
{
key
});
assert
.
notCalled
(
fakeFrameSync
.
scrollToAnnotation
);
});
});
});
describe
(
'keyboard focus request handling'
,
()
=>
{
[
null
,
'other-annotation'
].
forEach
(
focusRequest
=>
{
it
(
'does not focus thread if there is no matching focus request'
,
()
=>
{
...
...
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