Skip to content

Commit f19240e

Browse files
author
Stefano Malagò
committed
Added keyboard support for opening misconception description
1 parent 353b6e6 commit f19240e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

frontend/src/components/tagger_component/MisconceptionInfoButton.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React, {useState} from "react"
1+
import React, {useRef, useState} from "react"
22
import HelpIcon from "@material-ui/icons/Help";
33
import {Button, Popover} from "@material-ui/core";
44
import {createStyles, makeStyles} from "@material-ui/core/styles";
55
import stringEquals from "../../util/StringEquals";
66
import NoMisconception from "../../util/NoMisconception";
7+
import withKeyboard from "../../hooks/withKeyboard";
78

89
const useStyles = makeStyles(() =>
910
createStyles({
@@ -16,12 +17,14 @@ const useStyles = makeStyles(() =>
1617
interface Input {
1718
handled_element: number,
1819
tags: (string | null)[],
20+
keyboardIndex?: string
1921
}
2022

21-
function MisconceptionInfoButton({tags, handled_element}: Input){
22-
23+
function MisconceptionInfoButton({tags, handled_element, keyboardIndex}: Input) {
2324
const classes = useStyles()
2425

26+
const ref = useRef<HTMLButtonElement>(null)
27+
2528
const tag: (string | null) = tags[handled_element]
2629

2730
const should_display = () => {
@@ -43,14 +46,20 @@ function MisconceptionInfoButton({tags, handled_element}: Input){
4346
const id = open ? "simple-popover" : undefined;
4447
// end popup stuff
4548

49+
withKeyboard((command => {
50+
if (keyboardIndex != undefined && (command == '' + keyboardIndex + 'h')) {
51+
ref.current?.click()
52+
}
53+
}))
54+
4655
return (
4756
!should_display() ?
4857
<>
4958
<Button disabled={true} className={classes.root}>
5059
</Button>
5160
</> :
5261
<>
53-
<Button title={"Definition"} onClick={handle_click_popup} className={classes.root}>
62+
<Button title={"Definition"} ref={ref} onClick={handle_click_popup} className={classes.root}>
5463
<HelpIcon/>
5564
</Button>
5665
<Popover

frontend/src/components/v2/tagger_component/StaticSelectorView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function StaticSelectorView({
124124
<MisconceptionInfoButton
125125
handled_element={0}
126126
tags={[misconception]}
127+
keyboardIndex={'' + handledIndex}
127128
/>
128129
</>
129130
)

0 commit comments

Comments
 (0)