Skip to content

Commit 1b6c1fe

Browse files
Added navigation hint disabled based on the event
1 parent f09e612 commit 1b6c1fe

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

packages/text-annotator-react/src/TextAnnotatorPopup/TextAnnotatorPopup.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { useAnnotator, useSelection } from '@annotorious/react';
1717
import type { TextAnnotation, TextAnnotator } from '@recogito/text-annotator';
1818

19-
import { useAnnouncePopupOpening, useRestoreSelectionCaret } from '../hooks';
19+
import { useAnnouncePopupNavigation, useRestoreSelectionCaret } from '../hooks';
2020
import './TextAnnotatorPopup.css';
2121

2222
interface TextAnnotationPopupProps {
@@ -132,7 +132,16 @@ export const TextAnnotatorPopup: FC<TextAnnotationPopupProps> = (props) => {
132132
}, [update]);
133133

134134
useRestoreSelectionCaret({ floatingOpen: isOpen });
135-
useAnnouncePopupOpening({ message: popupNavigationMessage, floatingOpen: isOpen });
135+
136+
/**
137+
* Announce the navigation hint only on the keyboard selection,
138+
* because the focus isn't shifted to the popup automatically then
139+
*/
140+
useAnnouncePopupNavigation({
141+
disabled: event?.type !== 'keydown',
142+
floatingOpen: isOpen,
143+
message: popupNavigationMessage,
144+
});
136145

137146
return isOpen && selected.length > 0 ? (
138147
<FloatingPortal>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './useRestoreSelectionCaret';
2-
export * from './useAnnouncePopupOpening';
2+
export * from './useAnnouncePopupNavigation';

packages/text-annotator-react/src/hooks/useAnnouncePopupOpening.ts renamed to packages/text-annotator-react/src/hooks/useAnnouncePopupNavigation.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ import { exhaustiveUniqueRandom } from 'unique-random';
88
// Generate random numbers that do not repeat until the entire range has appeared
99
const uniqueRandom = exhaustiveUniqueRandom(1, 300);
1010

11-
export const useAnnouncePopupOpening = (args: { message?: string, floatingOpen: boolean }) => {
11+
interface AnnouncePopupOpeningArgs {
12+
message?: string;
13+
floatingOpen: boolean;
14+
disabled?: boolean;
15+
}
16+
17+
export const useAnnouncePopupNavigation = (args: AnnouncePopupOpeningArgs) => {
1218
const {
1319
message = 'Press Tab to move to Notes Dialog',
14-
floatingOpen
20+
floatingOpen,
21+
disabled = false
1522
} = args;
1623

1724
const store = useAnnotationStore();
@@ -47,7 +54,7 @@ export const useAnnouncePopupOpening = (args: { message?: string, floatingOpen:
4754
const idleTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
4855

4956
useEffect(() => {
50-
if (!floatingOpen || event?.type !== 'keydown' || !message) return;
57+
if (disabled || !floatingOpen || !message) return;
5158

5259
const scheduleIdleAnnouncement = () => {
5360
clearTimeout(idleTimeoutRef.current);

0 commit comments

Comments
 (0)