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"
@@ -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,18 @@ export const RegionLabel = ({
142151 />
143152 </ div >
144153 ) }
154+ { allowComments && < TextField
155+ InputProps = { {
156+ className : classes . commentBox ,
157+ } }
158+ fullWidth
159+ multiline
160+ rows = { 3 }
161+ ref = { commentInputRef }
162+ onClick = { onCommentInputClick }
163+ value = { region . comment || '' }
164+ onChange = { event => onChange ( { ...( region : any ) , comment : event . target . value } ) }
165+ /> }
145166 { onClose && (
146167 < div style = { { marginTop : 4 , display : "flex" } } >
147168 < div style = { { flexGrow : 1 } } />
0 commit comments