Commit e445b72d authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Prevent scrollToAnnotation when key pressed on ThreadCard children

parent 5baf673b
......@@ -82,8 +82,13 @@ function ThreadCard({ frameSync, thread }: ThreadCardProps) {
onMouseLeave={() => setThreadHovered(null)}
onKeyDown={e => {
// Simulate default button behavior, where `Enter` and `Space` trigger
// click action
if (['Enter', ' '].includes(e.key) && thread.annotation) {
// click action.
// Make sure the event was triggered on the card itself and not a children
if (
e.target === cardRef.current &&
['Enter', ' '].includes(e.key) &&
thread.annotation
) {
scrollToAnnotation(thread.annotation);
}
}}
......
......@@ -127,10 +127,23 @@ describe('ThreadCard', () => {
);
});
it('does not scroll to annotation when event target is not the Card', () => {
const wrapper = createComponent();
// Trigger keydown through the prop itself, as `target` cannot be
// overwritten on an event
wrapper.find(threadCardSelector).prop('onKeyDown')({
key,
target: 'foo',
});
assert.notCalled(fakeFrameSync.scrollToAnnotation);
});
it('does not scroll to annotation when it is not set', () => {
const wrapper = createComponent({ thread: {} });
wrapper.find(threadCardSelector).simulate('keypress', { key });
wrapper.find(threadCardSelector).simulate('keydown', { key });
assert.notCalled(fakeFrameSync.scrollToAnnotation);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment