Skip to content

Commit 2278b0c

Browse files
Conrad Chanmergify[bot]
andauthored
fix(highlights): Allows highlight anchors to receive focus (#598)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent d960269 commit 2278b0c

File tree

2 files changed

+0
-60
lines changed

2 files changed

+0
-60
lines changed

src/highlight/HighlightTarget.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as ReactRedux from 'react-redux';
33
import classNames from 'classnames';
44
import noop from 'lodash/noop';
55
import { getIsCurrentFileVersion } from '../store';
6-
import { MOUSE_PRIMARY } from '../constants';
76
import { Rect } from '../@types/model';
87
import './HighlightTarget.scss';
98

@@ -21,12 +20,6 @@ const HighlightTarget = (props: Props, ref: React.Ref<HighlightTargetRef>): JSX.
2120
const { annotationId, className, onHover = noop, onSelect = noop, shapes } = props;
2221
const isCurrentFileVersion = ReactRedux.useSelector(getIsCurrentFileVersion);
2322

24-
const handleClick = (event: React.MouseEvent<HighlightTargetRef>): void => {
25-
event.preventDefault();
26-
event.stopPropagation();
27-
event.nativeEvent.stopImmediatePropagation();
28-
};
29-
3023
const handleFocus = (): void => {
3124
onSelect(annotationId);
3225
};
@@ -39,17 +32,6 @@ const HighlightTarget = (props: Props, ref: React.Ref<HighlightTargetRef>): JSX.
3932
onHover(null);
4033
};
4134

42-
const handleMouseDown = (event: React.MouseEvent<HighlightTargetRef>): void => {
43-
if (event.buttons !== MOUSE_PRIMARY) {
44-
return;
45-
}
46-
47-
onSelect(annotationId);
48-
49-
event.preventDefault(); // Prevents focus from leaving the anchor immediately in some browsers
50-
event.nativeEvent.stopImmediatePropagation(); // Prevents document event handlers from executing
51-
};
52-
5335
return (
5436
// eslint-disable-next-line jsx-a11y/anchor-is-valid
5537
<a
@@ -60,9 +42,7 @@ const HighlightTarget = (props: Props, ref: React.Ref<HighlightTargetRef>): JSX.
6042
data-resin-target="highlightText"
6143
data-testid={`ba-AnnotationTarget-${annotationId}`}
6244
href="#"
63-
onClick={handleClick}
6445
onFocus={handleFocus}
65-
onMouseDown={handleMouseDown}
6646
onMouseEnter={handleMouseEnter}
6747
onMouseLeave={handleMouseLeave}
6848
role="button"

src/highlight/__tests__/HighlightTarget-test.tsx

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -57,46 +57,6 @@ describe('HighlightTarget', () => {
5757
expect(defaults.onSelect).toHaveBeenCalledWith(defaults.annotationId);
5858
});
5959

60-
describe('handleMouseDown()', () => {
61-
const mockEvent = {
62-
buttons: 1,
63-
preventDefault: jest.fn(),
64-
nativeEvent: {
65-
stopImmediatePropagation: jest.fn(),
66-
},
67-
};
68-
69-
test('should do nothing if button is not MOUSE_PRIMARY', () => {
70-
const wrapper = getWrapper();
71-
const anchor = wrapper.find('a');
72-
const event = {
73-
...mockEvent,
74-
buttons: 2,
75-
};
76-
77-
anchor.simulate('mousedown', event);
78-
79-
expect(defaults.onSelect).not.toHaveBeenCalled();
80-
expect(mockEvent.preventDefault).not.toHaveBeenCalled();
81-
expect(mockEvent.nativeEvent.stopImmediatePropagation).not.toHaveBeenCalled();
82-
});
83-
84-
test('should call onSelect', () => {
85-
const wrapper = getWrapper();
86-
const anchor = wrapper.find('a');
87-
const event = {
88-
...mockEvent,
89-
buttons: 1,
90-
};
91-
92-
anchor.simulate('mousedown', event);
93-
94-
expect(defaults.onSelect).toHaveBeenCalledWith(defaults.annotationId);
95-
expect(mockEvent.preventDefault).toHaveBeenCalled();
96-
expect(mockEvent.nativeEvent.stopImmediatePropagation).toHaveBeenCalled();
97-
});
98-
});
99-
10060
describe('handleMouseEnter()', () => {
10161
test('should call onHover with annotationId', () => {
10262
const wrapper = getWrapper();

0 commit comments

Comments
 (0)