Skip to content

Commit cfaa774

Browse files
committed
Enter key handled for rename project option
1 parent 2fd8b2b commit cfaa774

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

client/modules/IDE/components/SketchList.jsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ class SketchList extends React.Component {
2121
this.props.getProjects(this.props.username);
2222
this.state = {
2323
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)
2526
};
27+
28+
this.closeAllDropdowns = this.closeAllDropdowns.bind(this);
29+
this.closeAllRenameBoxes = this.closeAllRenameBoxes.bind(this);
30+
this.restoreRenameBoxContent = this.restoreRenameBoxContent.bind(this);
2631
}
2732

2833
getSketchesTitle() {
@@ -44,6 +49,12 @@ class SketchList extends React.Component {
4449
});
4550
}
4651

52+
restoreRenameBoxContent() {
53+
this.setState({
54+
renameBoxContent: this.props.sketches.map(({ name }) => name)
55+
});
56+
}
57+
4758
render() {
4859
const username = this.props.username !== undefined ? this.props.username : this.props.user.username;
4960
return (
@@ -96,7 +107,24 @@ class SketchList extends React.Component {
96107
{this.state.renameBoxDisplayed[i]
97108
&&
98109
<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}
99126
onClick={e => e.stopPropagation()}
127+
autoFocus //eslint-disable-line
100128
/>
101129
}
102130
</th>
@@ -107,6 +135,7 @@ class SketchList extends React.Component {
107135
className="sketch-list__dropdown-button"
108136
onClick={(e) => {
109137
e.stopPropagation();
138+
this.closeAllRenameBoxes();
110139
this.setState(() => {
111140
const actionDialogueDisplayed = new Array(this.props.sketches.length).fill(false);
112141
actionDialogueDisplayed[i] = true;

0 commit comments

Comments
 (0)