diff --git a/packages/core/src/components/TextArea/TextArea.tsx b/packages/core/src/components/TextArea/TextArea.tsx index 4051a11ab6..711651e050 100644 --- a/packages/core/src/components/TextArea/TextArea.tsx +++ b/packages/core/src/components/TextArea/TextArea.tsx @@ -1,4 +1,4 @@ -import React, { forwardRef, useCallback, useMemo, useState } from "react"; +import React, { forwardRef, useCallback, useEffect, useMemo, useState } from "react"; import cx from "classnames"; import { getTestId } from "../../tests/test-ids-utils"; import { ComponentDefaultTestId, ComponentVibeId } from "../../tests/constants"; @@ -50,6 +50,10 @@ const TextArea = forwardRef( const [characterCount, setCharacterCount] = useState(value?.length || 0); const isErrorState = error || (typeof maxLength === "number" && characterCount > maxLength); + useEffect(() => { + setCharacterCount(value?.length || 0); + }, [value]); + const handleOnChange = useCallback( (event: React.ChangeEvent) => { setCharacterCount(event.target.value.length);