textarea.tsx

Overview

textarea.tsx defines two React components, Textarea and BlurTextarea, that provide enhanced textarea input fields with advanced features such as automatic height adjustment and controlled blur-based updates. These components improve user experience by dynamically resizing to fit content and by controlling when changes propagate to parent components.


Components and Functions

Textarea

A forward-ref React component that renders a textarea input with optional auto-sizing behavior.

Props

Extends all standard HTML <textarea> attributes with an additional optional autoSize prop.

interface TextareaProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'autoSize'> {
  autoSize?: {
    minRows?: number;  // Minimum visible rows for the textarea
    maxRows?: number;  // Maximum visible rows for the textarea
  };
}

Behavior

Implementation Details

Usage Example

<Textarea
  autoSize={{ minRows: 2, maxRows: 6 }}
  placeholder="Type your message..."
/>

BlurTextarea

A forward-ref React component that wraps the Textarea component to provide controlled input behavior with deferred onChange invocation.

Props

Extends standard textarea props and requires:

Behavior

Usage Example

<BlurTextarea
  value={message}
  onChange={(newVal) => setMessage(newVal)}
  placeholder="Enter text and blur to save"
/>

Important Implementation Details and Algorithms


Interactions with Other Parts of the System


Visual Diagram

componentDiagram
    component Textarea {
        +props: TextareaProps
        +ref: React.Ref<HTMLTextAreaElement>
        -textareaRef: React.RefObject<HTMLTextAreaElement>
        -getLineHeight(element: HTMLElement): number
        -adjustHeight(): void
        +render(): JSX.Element
    }
    component BlurTextarea {
        +props: ComponentProps<'textarea'> & { value: Value; onChange(value: Value): void }
        +ref: React.Ref<HTMLTextAreaElement>
        -val: Value (state)
        -handleChange(e: ChangeEvent<HTMLTextAreaElement>): void
        -handleBlur(e: FocusEvent<HTMLTextAreaElement>): void
        +render(): JSX.Element
    }
    BlurTextarea --> Textarea : uses

Summary

This file is a foundational UI building block for handling multiline text input with enhanced control and styling in React applications.