Skip to content

Commit c19ae21

Browse files
authored
Merge pull request #1299 from nik72619c/rename-input-not-changing-focus
Fix focus not coming on clicking on the rename option
2 parents d8cac04 + d348f79 commit c19ae21

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

client/modules/IDE/components/CollectionList/CollectionListRow.jsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CollectionListRowBase extends React.Component {
2525
renameOpen: false,
2626
renameValue: '',
2727
};
28+
this.renameInput = React.createRef();
2829
}
2930

3031
onFocusComponent = () => {
@@ -89,7 +90,7 @@ class CollectionListRowBase extends React.Component {
8990
this.setState({
9091
renameOpen: true,
9192
renameValue: this.props.collection.name,
92-
});
93+
}, () => this.renameInput.current.focus());
9394
}
9495

9596
handleRenameChange = (e) => {
@@ -99,23 +100,23 @@ class CollectionListRowBase extends React.Component {
99100
}
100101

101102
handleRenameEnter = (e) => {
102-
const isValid = this.state.renameValue !== '';
103-
104103
if (e.key === 'Enter') {
105-
if (isValid) {
106-
this.props.editCollection(this.props.collection.id, { name: this.state.renameValue });
107-
}
108-
109-
// this.resetName();
104+
this.updateName();
110105
this.closeAll();
111106
}
112107
}
113108

114-
// resetName = () => {
115-
// this.setState({
116-
// renameValue: this.props.collection.name
117-
// });
118-
// }
109+
handleRenameBlur = () => {
110+
this.updateName();
111+
this.closeAll();
112+
}
113+
114+
updateName = () => {
115+
const isValid = this.state.renameValue.trim().length !== 0;
116+
if (isValid) {
117+
this.props.editCollection(this.props.collection.id, { name: this.state.renameValue.trim() });
118+
}
119+
}
119120

120121
renderActions = () => {
121122
const { optionsOpen } = this.state;
@@ -188,8 +189,9 @@ class CollectionListRowBase extends React.Component {
188189
value={renameValue}
189190
onChange={this.handleRenameChange}
190191
onKeyUp={this.handleRenameEnter}
191-
// onBlur={this.resetName}
192+
onBlur={this.handleRenameBlur}
192193
onClick={e => e.stopPropagation()}
194+
ref={this.renameInput}
193195
/>
194196
}
195197
</React.Fragment>

client/modules/IDE/components/SketchList.jsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class SketchListRowBase extends React.Component {
3232
renameValue: props.sketch.name,
3333
isFocused: false,
3434
};
35+
this.renameInput = React.createRef();
3536
}
3637

3738
onFocusComponent = () => {
@@ -69,8 +70,9 @@ class SketchListRowBase extends React.Component {
6970

7071
openRename = () => {
7172
this.setState({
72-
renameOpen: true
73-
});
73+
renameOpen: true,
74+
renameValue: this.props.sketch.name
75+
}, () => this.renameInput.current.focus());
7476
}
7577

7678
closeRename = () => {
@@ -94,15 +96,27 @@ class SketchListRowBase extends React.Component {
9496

9597
handleRenameEnter = (e) => {
9698
if (e.key === 'Enter') {
97-
// TODO pass this func
98-
this.props.changeProjectName(this.props.sketch.id, this.state.renameValue);
99+
this.updateName();
99100
this.closeAll();
100101
}
101102
}
102103

104+
handleRenameBlur = () => {
105+
this.updateName();
106+
this.closeAll();
107+
}
108+
109+
updateName = () => {
110+
const isValid = this.state.renameValue.trim().length !== 0;
111+
if (isValid) {
112+
this.props.changeProjectName(this.props.sketch.id, this.state.renameValue.trim());
113+
}
114+
}
115+
103116
resetSketchName = () => {
104117
this.setState({
105-
renameValue: this.props.sketch.name
118+
renameValue: this.props.sketch.name,
119+
renameOpen: false
106120
});
107121
}
108122

@@ -255,8 +269,9 @@ class SketchListRowBase extends React.Component {
255269
value={renameValue}
256270
onChange={this.handleRenameChange}
257271
onKeyUp={this.handleRenameEnter}
258-
onBlur={this.resetSketchName}
272+
onBlur={this.handleRenameBlur}
259273
onClick={e => e.stopPropagation()}
274+
ref={this.renameInput}
260275
/>
261276
}
262277
</React.Fragment>

0 commit comments

Comments
 (0)