refactor: improve template input

This commit is contained in:
Carlos Valente
2025-02-18 14:49:18 +01:00
committed by Carlos Valente
parent 5fb30c75c4
commit 6b2e45e7de
4 changed files with 18 additions and 12 deletions
@@ -33,13 +33,11 @@ const TemplateInput = forwardRef(function TemplateInput(props: TemplateInputProp
if (event.target.value.endsWith('{')) {
setShowSuggestions(true);
setSuggestions(updateSuggestions(event.target.value));
} else if (event.target.value === '' || event.target.value.endsWith('}}')) {
setShowSuggestions(false);
}
if (showSuggestions) {
const suggestions = updateSuggestions(event.target.value);
setSuggestions(suggestions);
} else if (showSuggestions) {
setSuggestions(updateSuggestions(event.target.value));
}
onChange?.(event);
@@ -55,7 +53,7 @@ const TemplateInput = forwardRef(function TemplateInput(props: TemplateInputProp
return (
<div className={style.wrapper} ref={mergeRefs(localRef, ref)}>
<Input {...rest} value={inputValue} onChange={handleInputChange} autoComplete='off' autoCorrect='off' />
<Input value={inputValue} {...rest} onChange={handleInputChange} autoComplete='off' autoCorrect='off' />
{showSuggestions && suggestions.length > 0 && (
<ul className={style.suggestions}>
{suggestions.map((suggestion) => (