File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed
packages/text-annotator-react/src Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ import {
16
16
import { useAnnotator , useSelection } from '@annotorious/react' ;
17
17
import type { TextAnnotation , TextAnnotator } from '@recogito/text-annotator' ;
18
18
19
- import { useAnnouncePopupOpening , useRestoreSelectionCaret } from '../hooks' ;
19
+ import { useAnnouncePopupNavigation , useRestoreSelectionCaret } from '../hooks' ;
20
20
import './TextAnnotatorPopup.css' ;
21
21
22
22
interface TextAnnotationPopupProps {
@@ -132,7 +132,16 @@ export const TextAnnotatorPopup: FC<TextAnnotationPopupProps> = (props) => {
132
132
} , [ update ] ) ;
133
133
134
134
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
+ } ) ;
136
145
137
146
return isOpen && selected . length > 0 ? (
138
147
< FloatingPortal >
Original file line number Diff line number Diff line change 1
1
export * from './useRestoreSelectionCaret' ;
2
- export * from './useAnnouncePopupOpening ' ;
2
+ export * from './useAnnouncePopupNavigation ' ;
Original file line number Diff line number Diff line change @@ -8,10 +8,17 @@ import { exhaustiveUniqueRandom } from 'unique-random';
8
8
// Generate random numbers that do not repeat until the entire range has appeared
9
9
const uniqueRandom = exhaustiveUniqueRandom ( 1 , 300 ) ;
10
10
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 ) => {
12
18
const {
13
19
message = 'Press Tab to move to Notes Dialog' ,
14
- floatingOpen
20
+ floatingOpen,
21
+ disabled = false
15
22
} = args ;
16
23
17
24
const store = useAnnotationStore ( ) ;
@@ -47,7 +54,7 @@ export const useAnnouncePopupOpening = (args: { message?: string, floatingOpen:
47
54
const idleTimeoutRef = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
48
55
49
56
useEffect ( ( ) => {
50
- if ( ! floatingOpen || event ?. type !== 'keydown' || ! message ) return ;
57
+ if ( disabled || ! floatingOpen || ! message ) return ;
51
58
52
59
const scheduleIdleAnnouncement = ( ) => {
53
60
clearTimeout ( idleTimeoutRef . current ) ;
You can’t perform that action at this time.
0 commit comments