1
- import React , { useState } from "react"
1
+ import React , { useRef , useState } from "react"
2
2
import HelpIcon from "@material-ui/icons/Help" ;
3
3
import { Button , Popover } from "@material-ui/core" ;
4
4
import { createStyles , makeStyles } from "@material-ui/core/styles" ;
5
5
import stringEquals from "../../util/StringEquals" ;
6
6
import NoMisconception from "../../util/NoMisconception" ;
7
+ import withKeyboard from "../../hooks/withKeyboard" ;
7
8
8
9
const useStyles = makeStyles ( ( ) =>
9
10
createStyles ( {
@@ -16,12 +17,14 @@ const useStyles = makeStyles(() =>
16
17
interface Input {
17
18
handled_element : number ,
18
19
tags : ( string | null ) [ ] ,
20
+ keyboardIndex ?: string
19
21
}
20
22
21
- function MisconceptionInfoButton ( { tags, handled_element} : Input ) {
22
-
23
+ function MisconceptionInfoButton ( { tags, handled_element, keyboardIndex} : Input ) {
23
24
const classes = useStyles ( )
24
25
26
+ const ref = useRef < HTMLButtonElement > ( null )
27
+
25
28
const tag : ( string | null ) = tags [ handled_element ]
26
29
27
30
const should_display = ( ) => {
@@ -43,14 +46,20 @@ function MisconceptionInfoButton({tags, handled_element}: Input){
43
46
const id = open ? "simple-popover" : undefined ;
44
47
// end popup stuff
45
48
49
+ withKeyboard ( ( command => {
50
+ if ( keyboardIndex != undefined && ( command == '' + keyboardIndex + 'h' ) ) {
51
+ ref . current ?. click ( )
52
+ }
53
+ } ) )
54
+
46
55
return (
47
56
! should_display ( ) ?
48
57
< >
49
58
< Button disabled = { true } className = { classes . root } >
50
59
</ Button >
51
60
</ > :
52
61
< >
53
- < Button title = { "Definition" } onClick = { handle_click_popup } className = { classes . root } >
62
+ < Button title = { "Definition" } ref = { ref } onClick = { handle_click_popup } className = { classes . root } >
54
63
< HelpIcon />
55
64
</ Button >
56
65
< Popover
0 commit comments