Skip to content

Commit 909ff92

Browse files
authored
Added ESC key binding (#1695)
* added ESC key binding for new row * added more conditions for cancellling editing rows * updated cancelling editing condition
1 parent 457a17d commit 909ff92

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/dashboard/Data/Browser/Browser.react.js

+10
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class Browser extends DashboardView {
121121
this.closeEditRowDialog = this.closeEditRowDialog.bind(this);
122122
this.handleShowAcl = this.handleShowAcl.bind(this);
123123
this.onDialogToggle = this.onDialogToggle.bind(this);
124+
this.abortAddRow = this.abortAddRow.bind(this);
124125
}
125126

126127
componentWillMount() {
@@ -294,6 +295,14 @@ class Browser extends DashboardView {
294295
}
295296
}
296297

298+
abortAddRow(){
299+
if(this.state.newObject){
300+
this.setState({
301+
newObject: null
302+
});
303+
}
304+
}
305+
297306
addRowWithModal() {
298307
this.addRow();
299308
this.selectRow(undefined, true);
@@ -1025,6 +1034,7 @@ class Browser extends DashboardView {
10251034
onCloneSelectedRows={this.showCloneSelectedRowsDialog}
10261035
onEditSelectedRow={this.showEditRowDialog}
10271036
onEditPermissions={this.onDialogToggle}
1037+
onAbortAddRow={this.abortAddRow}
10281038

10291039
columns={columns}
10301040
className={className}

src/dashboard/Data/Browser/DataBrowser.react.js

+23
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,29 @@ export default class DataBrowser extends React.Component {
138138
if (this.props.disableKeyControls) {
139139
return;
140140
}
141+
if (
142+
this.state.editing &&
143+
this.state.current &&
144+
this.state.current.row === -1 &&
145+
this.props.newObject
146+
) {
147+
// if user is editing new row and want to cancel editing cell
148+
if (e.keyCode === 27) {
149+
this.setState({
150+
editing: false
151+
});
152+
e.preventDefault();
153+
}
154+
return;
155+
}
156+
if(!this.state.editing && this.props.newObject){
157+
// if user is not editing any row but there's new row
158+
if(e.keyCode === 27){
159+
this.props.onAbortAddRow();
160+
e.preventDefault();
161+
}
162+
return;
163+
}
141164
if (this.state.editing) {
142165
switch (e.keyCode) {
143166
case 27: // ESC

0 commit comments

Comments
 (0)