@@ -21,8 +21,13 @@ class SketchList extends React.Component {
21
21
this . props . getProjects ( this . props . username ) ;
22
22
this . state = {
23
23
actionDialogueDisplayed : new Array ( this . props . sketches . length ) . fill ( false ) ,
24
- renameBoxDisplayed : new Array ( this . props . sketches . length ) . fill ( false )
24
+ renameBoxDisplayed : new Array ( this . props . sketches . length ) . fill ( false ) ,
25
+ renameBoxContent : this . props . sketches . map ( ( { name } ) => name )
25
26
} ;
27
+
28
+ this . closeAllDropdowns = this . closeAllDropdowns . bind ( this ) ;
29
+ this . closeAllRenameBoxes = this . closeAllRenameBoxes . bind ( this ) ;
30
+ this . restoreRenameBoxContent = this . restoreRenameBoxContent . bind ( this ) ;
26
31
}
27
32
28
33
getSketchesTitle ( ) {
@@ -44,6 +49,12 @@ class SketchList extends React.Component {
44
49
} ) ;
45
50
}
46
51
52
+ restoreRenameBoxContent ( ) {
53
+ this . setState ( {
54
+ renameBoxContent : this . props . sketches . map ( ( { name } ) => name )
55
+ } ) ;
56
+ }
57
+
47
58
render ( ) {
48
59
const username = this . props . username !== undefined ? this . props . username : this . props . user . username ;
49
60
return (
@@ -96,7 +107,24 @@ class SketchList extends React.Component {
96
107
{ this . state . renameBoxDisplayed [ i ]
97
108
&&
98
109
< input
110
+ value = { this . state . renameBoxContent [ i ] }
111
+ onChange = { ( e ) => {
112
+ const renameBoxContent = [ ...this . state . renameBoxContent ] ;
113
+ renameBoxContent [ i ] = e . target . value ;
114
+ this . setState ( {
115
+ renameBoxContent
116
+ } ) ;
117
+ } }
118
+ onKeyUp = { ( e ) => {
119
+ // Enter pressed
120
+ if ( e . key === 'Enter' ) {
121
+ this . restoreRenameBoxContent ( ) ;
122
+ this . closeAllRenameBoxes ( ) ;
123
+ }
124
+ } }
125
+ onBlur = { this . restoreRenameBoxContent }
99
126
onClick = { e => e . stopPropagation ( ) }
127
+ autoFocus //eslint-disable-line
100
128
/>
101
129
}
102
130
</ th >
@@ -107,6 +135,7 @@ class SketchList extends React.Component {
107
135
className = "sketch-list__dropdown-button"
108
136
onClick = { ( e ) => {
109
137
e . stopPropagation ( ) ;
138
+ this . closeAllRenameBoxes ( ) ;
110
139
this . setState ( ( ) => {
111
140
const actionDialogueDisplayed = new Array ( this . props . sketches . length ) . fill ( false ) ;
112
141
actionDialogueDisplayed [ i ] = true ;
0 commit comments