Skip to content

Commit 4482c3c

Browse files
committed
[Web] Test if focus method exists before using it
1 parent 9f6a341 commit 4482c3c

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/components/JsonAddValue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class JsonAddValue extends Component {
5050
const { inputRefKey, inputRefValue } = this.state;
5151
const { onlyValue } = this.props;
5252

53-
if (inputRefKey) {
53+
if (inputRefKey && (typeof inputRefKey.focus === 'function')) {
5454
inputRefKey.focus();
5555
}
5656

57-
if (onlyValue && inputRefValue) {
57+
if (onlyValue && inputRefValue && (typeof inputRefValue.focus === 'function')) {
5858
inputRefValue.focus();
5959
}
6060
}

src/components/JsonFunctionValue.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class JsonValue extends Component {
7777
const { editEnabled, inputRef } = this.state;
7878
const { readOnly } = this.props;
7979

80-
if (editEnabled && !readOnly) {
80+
if (editEnabled && !readOnly && (typeof inputRef.focus === 'function')) {
8181
inputRef.focus();
8282
}
8383
}
@@ -142,13 +142,13 @@ class JsonValue extends Component {
142142
const cancelButtonElementLayout = React.cloneElement(cancelButtonElement, {
143143
onClick: this.handleCancelEdit,
144144
});
145-
const inputElementLayout = React.cloneElement(textareaElement, {
145+
const textareaElementLayout = React.cloneElement(textareaElement, {
146146
ref: this.refInput,
147147
defaultValue: originalValue,
148148
});
149149

150150
result = (<span className="rejt-edit-form" style={style.editForm}>
151-
{inputElementLayout} {cancelButtonElementLayout}{editButtonElementLayout}
151+
{textareaElementLayout} {cancelButtonElementLayout}{editButtonElementLayout}
152152
</span>);
153153
minusElement = null;
154154
} else {

src/components/JsonValue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class JsonValue extends Component {
7777
const { editEnabled, inputRef } = this.state;
7878
const { readOnly } = this.props;
7979

80-
if (editEnabled && !readOnly) {
80+
if (editEnabled && !readOnly && (typeof inputRef.focus === 'function')) {
8181
inputRef.focus();
8282
}
8383
}

0 commit comments

Comments
 (0)