import { TextField } from '@mui/material'; import { WidgetProps } from '@rjsf/utils'; import React, { useCallback } from 'react'; /** * Textarea widget that shows 1 row when empty, configured rows when has content * Allows manual resizing by dragging */ export const AutoResizeTextareaWidget: React.FC = ({ id, value = '', onChange, onBlur, onFocus, disabled, readonly, required, placeholder, uiSchema, }) => { const handleChange = useCallback((event: React.ChangeEvent) => { onChange(event.target.value); }, [onChange]); const handleBlur = useCallback((event: React.FocusEvent) => { onBlur(id, event.target.value); }, [onBlur, id]); const handleFocus = useCallback((event: React.FocusEvent) => { onFocus(id, event.target.value); }, [onFocus, id]); // Get configured rows from uiSchema, default to 4 for content const uiOptions = uiSchema?.['ui:options'] as Record | undefined; const configuredRows = typeof uiOptions?.rows === 'number' ? uiOptions.rows : 4; // Use 1 row when empty, configured rows when has content const isEmpty = !value || String(value).trim() === ''; const minRows = isEmpty ? 1 : configuredRows; return ( ); };