// Copyright (c) Meta Platforms, Inc. and affiliates. 'use client'; import {forwardRef, useEffect, useRef, useState} from 'react'; import {Button} from '@astryxdesign/core/Button'; import {Card} from '@astryxdesign/core/Card'; import {useMergedRefs} from '@astryxdesign/core/hooks'; import {VStack} from '@astryxdesign/core/Layout'; type AutoGrowTextAreaProps = { value: string; onChange: (value: string) => void; }; // Forwards the caller's ref and also keeps its own ref to measure // scrollHeight; useMergedRefs attaches both to the same textarea. const AutoGrowTextArea = forwardRef( function AutoGrowTextArea({value, onChange}, forwardedRef) { const keptRef = useRef(null); const mergedRef = useMergedRefs(forwardedRef, keptRef); // Syncs the textarea's inline height with the committed value. // scrollHeight is right only after React writes the new text. useEffect(() => { const el = keptRef.current; if (!el) { return; } el.style.height = 'auto'; el.style.height = `${el.scrollHeight}px`; }, [value]); return (