import { useEffect, useRef } from 'react' import cn from '@/utils/classnames' type AutoHeightTextareaProps = & React.DetailedHTMLProps, HTMLTextAreaElement> & { outerClassName?: string } const AutoHeightTextarea = ( { ref: outRef, outerClassName, value, className, placeholder, autoFocus, disabled, ...rest }: AutoHeightTextareaProps & { ref: React.RefObject; }, ) => { const innerRef = useRef(null) const ref = outRef || innerRef useEffect(() => { if (autoFocus && !disabled && value) { if (typeof ref !== 'function') { ref.current?.setSelectionRange(`${value}`.length, `${value}`.length) ref.current?.focus() } } }, [autoFocus, disabled, ref]) return ( (
{!value ? placeholder : `${value}`.replace(/\n$/, '\n ')}