From a9b67ff9ff150f60892a8f189e3b1c6c244680eb Mon Sep 17 00:00:00 2001 From: Ilya Y <75578537+ilya-bkv@users.noreply.github.com> Date: Thu, 21 Sep 2023 08:46:32 +0300 Subject: [PATCH] GrowingTextarea: initial value fix (#228) --- .../_shared/GrowingTextarea/GrowingTextarea.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/_shared/GrowingTextarea/GrowingTextarea.tsx b/src/components/_shared/GrowingTextarea/GrowingTextarea.tsx index fb757de0..dd5313f0 100644 --- a/src/components/_shared/GrowingTextarea/GrowingTextarea.tsx +++ b/src/components/_shared/GrowingTextarea/GrowingTextarea.tsx @@ -20,7 +20,7 @@ export const GrowingTextarea = (props: Props) => { createEffect(() => { if (props.maxLength && props.initialValue?.length > props.maxLength) { - setValue(props.initialValue.slice(0, props.maxLength)) + setValue(props.initialValue?.slice(0, props.maxLength)) } else { setValue(props.initialValue ?? '') } @@ -39,6 +39,8 @@ export const GrowingTextarea = (props: Props) => { } } + console.log('!!! initialValue:', props.initialValue) + return (
{ maxlength={props.maxLength} autocomplete="off" class={clsx(styles.textInput, props.class)} - value={props.maxLength ? props.initialValue.slice(0, props.maxLength) : props.initialValue} + value={ + props.initialValue && props.maxLength + ? props.initialValue?.slice(0, props.maxLength) + : props.initialValue + } onKeyDown={props.allowEnterKey ? handleKeyDown : null} onInput={(event) => handleChangeValue(event)} onChange={(event) => props.value(event.target.value)}