Fix undefined value case

This commit is contained in:
Rafael 2022-04-25 14:21:54 -03:00 committed by Thomas Zarebczan
parent 5787bfcf2f
commit 7390c464ac

View file

@ -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;