import * as React from "react" import { cn } from "../core/cn" interface TextareaProps extends React.ComponentPropsWithoutRef<"textarea"> { autoResize?: boolean } const Textarea = React.forwardRef( ({ className, autoResize = false, onChange, ...props }, ref) => { const internalRef = React.useRef(null) const resolvedRef = (ref as React.RefObject) ?? internalRef const handleChange = React.useCallback( (e: React.ChangeEvent) => { if (autoResize && resolvedRef.current) { resolvedRef.current.style.height = "auto" resolvedRef.current.style.height = `${resolvedRef.current.scrollHeight}px` } onChange?.(e) }, [autoResize, onChange, resolvedRef] ) return (