import React, { useEffect, useRef, ChangeEvent } from 'react'; interface Props { value: string; onChange: (value: string) => void; className?: string; placeholder?: string; } const AutoExpandingTextInput: React.FC = ({ value, className, onChange, placeholder }) => { const inputRef = useRef(null); const measureRef = useRef(null); const adjustWidth = () => { const input = inputRef.current; const measure = measureRef.current; if (input && measure) { measure.textContent = input.value || placeholder || ''; input.style.width = `${measure.offsetWidth + 10}px`; } }; useEffect(() => { adjustWidth(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [value, placeholder]); const handleChange = (e: ChangeEvent) => { onChange(e.target.value); adjustWidth(); }; return (
); }; export default AutoExpandingTextInput;