box-annotations 5.2.1-beta.5 → 5.2.1-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "box-annotations",
3
- "version": "5.2.1-beta.5",
3
+ "version": "5.2.1-beta.6",
4
4
  "description": "Box Annotations",
5
5
  "author": "Box (https://www.box.com/)",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -8,8 +8,8 @@ import './BoundingBoxHighlightNav.scss';
8
8
  type Props = {
9
9
  currentIndex: number;
10
10
  total: number;
11
- onPrev: (event: React.MouseEvent) => void;
12
- onNext: (event: React.MouseEvent) => void;
11
+ onPrev: (event: React.MouseEvent | KeyboardEvent) => void;
12
+ onNext: (event: React.MouseEvent | KeyboardEvent) => void;
13
13
  };
14
14
 
15
15
  const BoundingBoxHighlightNav = ({ currentIndex, total, onPrev, onNext }: Props): JSX.Element => {
@@ -17,6 +17,25 @@ const BoundingBoxHighlightNav = ({ currentIndex, total, onPrev, onNext }: Props)
17
17
  const isPrevDisabled = currentIndex === 0;
18
18
  const isNextDisabled = currentIndex === total - 1;
19
19
 
20
+ React.useEffect(() => {
21
+ const handleKeyDown = (event: KeyboardEvent): void => {
22
+ if (event.key === 'ArrowLeft') {
23
+ event.stopPropagation();
24
+ if (!isPrevDisabled) {
25
+ onPrev(event);
26
+ }
27
+ } else if (event.key === 'ArrowRight') {
28
+ event.stopPropagation();
29
+ if (!isNextDisabled) {
30
+ onNext(event);
31
+ }
32
+ }
33
+ };
34
+
35
+ document.addEventListener('keydown', handleKeyDown, { capture: true });
36
+ return () => document.removeEventListener('keydown', handleKeyDown, { capture: true });
37
+ }, [isPrevDisabled, isNextDisabled, onPrev, onNext]);
38
+
20
39
  return (
21
40
  <div className="ba-BoundingBoxHighlightNav" data-testid="ba-BoundingBoxHighlightNav">
22
41
  <button
@@ -40,14 +40,14 @@ const BoundingBoxHighlightRect = ({
40
40
  onSelect?.(id);
41
41
  };
42
42
 
43
- const handlePrev = (event: React.MouseEvent): void => {
43
+ const handlePrev = (event: React.MouseEvent | KeyboardEvent): void => {
44
44
  event.stopPropagation();
45
45
  if (prevId) {
46
46
  onNavigate?.(prevId);
47
47
  }
48
48
  };
49
49
 
50
- const handleNext = (event: React.MouseEvent): void => {
50
+ const handleNext = (event: React.MouseEvent | KeyboardEvent): void => {
51
51
  event.stopPropagation();
52
52
  if (nextId) {
53
53
  onNavigate?.(nextId);