11// @flow
22
3- import React , { useState , memo } from "react"
3+ import React , { useRef , memo } from "react"
44import Paper from "@material-ui/core/Paper"
55import { makeStyles } from "@material-ui/core/styles"
66import styles from "./styles"
@@ -10,7 +10,7 @@ import IconButton from "@material-ui/core/IconButton"
1010import Button from "@material-ui/core/Button"
1111import TrashIcon from "@material-ui/icons/Delete"
1212import CheckIcon from "@material-ui/icons/Check"
13- import UndoIcon from "@material-ui/icons/Undo "
13+ import TextField from "@material-ui/core/TextField "
1414import Select from "react-select"
1515import CreatableSelect from "react-select/creatable"
1616
@@ -30,6 +30,7 @@ type Props = {
3030 onClose : ( Region ) => null ,
3131 onOpen : ( Region ) => null ,
3232 onRegionClassAdded : ( ) => { } ,
33+ allowComments ?: boolean ,
3334}
3435
3536export const RegionLabel = ( {
@@ -42,8 +43,16 @@ export const RegionLabel = ({
4243 onClose,
4344 onOpen,
4445 onRegionClassAdded,
46+ allowComments,
4547} : Props ) => {
4648 const classes = useStyles ( )
49+ const commentInputRef = useRef ( null )
50+ const onCommentInputClick = ( _ ) => {
51+ // The TextField wraps the <input> tag with two divs
52+ const commentInput = commentInputRef . current . children [ 0 ] . children [ 0 ]
53+
54+ if ( commentInput ) return commentInput . focus ( )
55+ }
4756
4857 return (
4958 < Paper
@@ -142,6 +151,22 @@ export const RegionLabel = ({
142151 />
143152 </ div >
144153 ) }
154+ { allowComments && (
155+ < TextField
156+ InputProps = { {
157+ className : classes . commentBox ,
158+ } }
159+ fullWidth
160+ multiline
161+ rows = { 3 }
162+ ref = { commentInputRef }
163+ onClick = { onCommentInputClick }
164+ value = { region . comment || "" }
165+ onChange = { ( event ) =>
166+ onChange ( { ...( region : any ) , comment : event . target . value } )
167+ }
168+ />
169+ ) }
145170 { onClose && (
146171 < div style = { { marginTop : 4 , display : "flex" } } >
147172 < div style = { { flexGrow : 1 } } />
0 commit comments