diff --git a/src/components/DateTimeEditor/DateTimeEditor.react.js b/src/components/DateTimeEditor/DateTimeEditor.react.js
index 3799d845e0..d4ede599d7 100644
--- a/src/components/DateTimeEditor/DateTimeEditor.react.js
+++ b/src/components/DateTimeEditor/DateTimeEditor.react.js
@@ -33,12 +33,14 @@ export default class DateTimeEditor extends React.Component {
componentDidMount() {
document.body.addEventListener('click', this.checkExternalClick);
- this.inputRef.current.addEventListener('keypress', this.handleKey);
+ document.body.addEventListener('touchend', this.checkExternalClick);
+ this.inputRef.current.addEventListener('keydown', this.handleKey);
}
componentWillUnmount() {
document.body.removeEventListener('click', this.checkExternalClick);
- this.inputRef.current.removeEventListener('keypress', this.handleKey);
+ document.body.removeEventListener('touchend', this.checkExternalClick);
+ this.inputRef.current.removeEventListener('keydown', this.handleKey);
}
checkExternalClick(e) {
@@ -51,6 +53,16 @@ export default class DateTimeEditor extends React.Component {
if (e.keyCode === 13) {
this.commitDate();
this.props.onCommit(this.state.value);
+ e.preventDefault();
+ } else if (e.keyCode === 27) {
+ // ESC key - cancel editing
+ if (this.props.onCancel) {
+ this.props.onCancel();
+ } else {
+ this.props.onCommit(this.props.value);
+ }
+ e.preventDefault();
+ e.stopPropagation();
}
}
diff --git a/src/components/GeoPointEditor/GeoPointEditor.react.js b/src/components/GeoPointEditor/GeoPointEditor.react.js
index 76ec915aa3..a0737425c5 100644
--- a/src/components/GeoPointEditor/GeoPointEditor.react.js
+++ b/src/components/GeoPointEditor/GeoPointEditor.react.js
@@ -32,8 +32,8 @@ export default class GeoPointEditor extends React.Component {
this.latitudeRef.current.focus();
}
this.latitudeRef.current.setSelectionRange(0, String(this.state.latitude).length);
- this.latitudeRef.current.addEventListener('keypress', this.handleKeyLatitude);
- this.longitudeRef.current.addEventListener('keypress', this.handleKeyLongitude);
+ this.latitudeRef.current.addEventListener('keydown', this.handleKeyLatitude);
+ this.longitudeRef.current.addEventListener('keydown', this.handleKeyLongitude);
}
componentWillReceiveProps(props) {
@@ -48,8 +48,8 @@ export default class GeoPointEditor extends React.Component {
}
componentWillUnmount() {
- this.latitudeRef.current.removeEventListener('keypress', this.handleKeyLatitude);
- this.longitudeRef.current.removeEventListener('keypress', this.handleKeyLongitude);
+ this.latitudeRef.current.removeEventListener('keydown', this.handleKeyLatitude);
+ this.longitudeRef.current.removeEventListener('keydown', this.handleKeyLongitude);
}
checkExternalClick() {
@@ -73,12 +73,32 @@ export default class GeoPointEditor extends React.Component {
if (e.keyCode === 13 || e.keyCode === 44) {
this.longitudeRef.current.focus();
this.longitudeRef.current.setSelectionRange(0, String(this.state.longitude).length);
+ e.preventDefault();
+ } else if (e.keyCode === 27) {
+ // ESC key - cancel editing
+ if (this.props.onCancel) {
+ this.props.onCancel();
+ } else {
+ this.props.onCommit(this.props.value);
+ }
+ e.preventDefault();
+ e.stopPropagation();
}
}
handleKeyLongitude(e) {
if (e.keyCode === 13) {
this.commitValue();
+ e.preventDefault();
+ } else if (e.keyCode === 27) {
+ // ESC key - cancel editing
+ if (this.props.onCancel) {
+ this.props.onCancel();
+ } else {
+ this.props.onCommit(this.props.value);
+ }
+ e.preventDefault();
+ e.stopPropagation();
}
}
diff --git a/src/components/NumberEditor/NumberEditor.react.js b/src/components/NumberEditor/NumberEditor.react.js
index 50b8771f57..d86e5fe26a 100644
--- a/src/components/NumberEditor/NumberEditor.react.js
+++ b/src/components/NumberEditor/NumberEditor.react.js
@@ -25,12 +25,14 @@ export default class NumberEditor extends React.Component {
componentDidMount() {
this.inputRef.current.setSelectionRange(0, String(this.state.value).length);
document.body.addEventListener('click', this.checkExternalClick);
- document.body.addEventListener('keypress', this.handleKey);
+ document.body.addEventListener('touchend', this.checkExternalClick);
+ document.body.addEventListener('keydown', this.handleKey);
}
componentWillUnmount() {
document.body.removeEventListener('click', this.checkExternalClick);
- document.body.removeEventListener('keypress', this.handleKey);
+ document.body.removeEventListener('touchend', this.checkExternalClick);
+ document.body.removeEventListener('keydown', this.handleKey);
}
checkExternalClick(e) {
@@ -42,6 +44,17 @@ export default class NumberEditor extends React.Component {
handleKey(e) {
if (e.keyCode === 13) {
this.commitValue();
+ e.preventDefault();
+ } else if (e.keyCode === 27) {
+ // ESC key - cancel editing
+ if (this.props.onCancel) {
+ this.props.onCancel();
+ } else {
+ // If no onCancel callback, commit the original value
+ this.props.onCommit(this.props.value);
+ }
+ e.preventDefault();
+ e.stopPropagation();
}
}
diff --git a/src/components/StringEditor/StringEditor.react.js b/src/components/StringEditor/StringEditor.react.js
index d36fdb296b..5c10d71ed4 100644
--- a/src/components/StringEditor/StringEditor.react.js
+++ b/src/components/StringEditor/StringEditor.react.js
@@ -24,12 +24,14 @@ export default class StringEditor extends React.Component {
componentDidMount() {
this.inputRef.current.setSelectionRange(0, this.state.value.length);
document.body.addEventListener('click', this.checkExternalClick);
- document.body.addEventListener('keypress', this.handleKey);
+ document.body.addEventListener('touchend', this.checkExternalClick);
+ document.body.addEventListener('keydown', this.handleKey);
}
componentWillUnmount() {
document.body.removeEventListener('click', this.checkExternalClick);
- document.body.removeEventListener('keypress', this.handleKey);
+ document.body.removeEventListener('touchend', this.checkExternalClick);
+ document.body.removeEventListener('keydown', this.handleKey);
}
checkExternalClick(e) {
@@ -44,7 +46,18 @@ export default class StringEditor extends React.Component {
// Otherwise, we submit
if (!this.props.multiline || !e.shiftKey) {
this.props.onCommit(this.state.value);
+ e.preventDefault();
}
+ } else if (e.keyCode === 27) {
+ // ESC key - cancel editing
+ if (this.props.onCancel) {
+ this.props.onCancel();
+ } else {
+ // If no onCancel callback, just commit the original value
+ this.props.onCommit(this.props.value);
+ }
+ e.preventDefault();
+ e.stopPropagation();
}
}
diff --git a/src/dashboard/Data/Browser/Editor.react.js b/src/dashboard/Data/Browser/Editor.react.js
index 74858e6c93..6ea2f3b57a 100644
--- a/src/dashboard/Data/Browser/Editor.react.js
+++ b/src/dashboard/Data/Browser/Editor.react.js
@@ -26,6 +26,7 @@ const Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit
multiline={!readonly}
width={width}
onCommit={onCommit}
+ onCancel={onCancel}
resizable={true}
/>
);
@@ -45,6 +46,7 @@ const Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit
multiline={true}
width={width}
onCommit={encodeCommit}
+ onCancel={onCancel}
/>
);
} else if (type === 'Polygon') {
@@ -83,6 +85,7 @@ const Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit
multiline={true}
width={width}
onCommit={encodeCommit}
+ onCancel={onCancel}
/>
);
} else if (type === 'Date') {
@@ -93,17 +96,18 @@ const Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit
readonly={true}
width={width}
onCommit={() => onCommit(value)}
+ onCancel={onCancel}
/>
);
} else {
- content =