Fix undefined value case
This commit is contained in:
parent
5787bfcf2f
commit
7390c464ac
1 changed files with 8 additions and 5 deletions
|
@ -90,7 +90,7 @@ export default function TextareaWithSuggestions(props: Props) {
|
||||||
placeholder,
|
placeholder,
|
||||||
searchQuery,
|
searchQuery,
|
||||||
type,
|
type,
|
||||||
value: messageValue,
|
value: messageValue = '',
|
||||||
autoFocus,
|
autoFocus,
|
||||||
submitButtonRef,
|
submitButtonRef,
|
||||||
spellCheck,
|
spellCheck,
|
||||||
|
@ -274,14 +274,17 @@ export default function TextareaWithSuggestions(props: Props) {
|
||||||
if (!suggestionValue) return;
|
if (!suggestionValue) return;
|
||||||
|
|
||||||
const elem = inputRef && inputRef.current;
|
const elem = inputRef && inputRef.current;
|
||||||
|
// $FlowFixMe
|
||||||
const newCursorPos = suggestionValue.beforeTerm.length + suggestionValue.index + selectedValue.length + 1;
|
const newCursorPos = suggestionValue.beforeTerm.length + suggestionValue.index + selectedValue.length + 1;
|
||||||
|
|
||||||
|
// $FlowFixMe
|
||||||
const contentBegin = messageValue.substring(0, suggestionValue.index);
|
const contentBegin = messageValue.substring(0, suggestionValue.index);
|
||||||
|
// $FlowFixMe
|
||||||
const replaceValue = suggestionValue.beforeTerm + selectedValue;
|
const replaceValue = suggestionValue.beforeTerm + selectedValue;
|
||||||
const contentEnd =
|
// $FlowFixMe
|
||||||
messageValue.length > suggestionValue.lastIndex
|
const endTo = messageValue.substring(suggestionValue.lastIndex, messageValue.length);
|
||||||
? messageValue.substring(suggestionValue.lastIndex, messageValue.length)
|
// $FlowFixMe
|
||||||
: ' ';
|
const contentEnd = messageValue.length > suggestionValue.lastIndex ? endTo : ' ';
|
||||||
|
|
||||||
const newValue = contentBegin + replaceValue + contentEnd;
|
const newValue = contentBegin + replaceValue + contentEnd;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue