File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
packages/react-dev-overlay/src/internal/components/Dialog Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,37 @@ const Dialog: React.FC<DialogProps> = function Dialog({
20
20
} , [ ] )
21
21
useOnClickOutside ( dialog , onClose )
22
22
23
+ // Make HTMLElements with `role=link` accessible to be triggered by the
24
+ // keyboard, i.e. [Enter].
25
+ React . useEffect ( ( ) => {
26
+ if ( dialog == null ) {
27
+ return
28
+ }
29
+
30
+ const root = dialog . getRootNode ( )
31
+ // Always true, but we do this for TypeScript:
32
+ if ( ! ( root instanceof ShadowRoot ) ) {
33
+ return
34
+ }
35
+ const shadowRoot = root
36
+ function handler ( e : KeyboardEvent ) {
37
+ const el = shadowRoot . activeElement
38
+ if (
39
+ e . key === 'Enter' &&
40
+ el instanceof HTMLElement &&
41
+ el . getAttribute ( 'role' ) === 'link'
42
+ ) {
43
+ e . preventDefault ( )
44
+ e . stopPropagation ( )
45
+
46
+ el . click ( )
47
+ }
48
+ }
49
+
50
+ shadowRoot . addEventListener ( 'keydown' , handler )
51
+ return ( ) => shadowRoot . removeEventListener ( 'keydown' , handler )
52
+ } , [ dialog ] )
53
+
23
54
return (
24
55
< div
25
56
ref = { onDialog }
You can’t perform that action at this time.
0 commit comments