Skip to main content

Overview

The ChatInput component provides the main user input interface for the chat application. It features an auto-resizing textarea, submit button, reset button, and displays a footer with project information. The component handles keyboard shortcuts (Enter to submit, Shift+Enter for new lines) and automatically focuses on load.

Props

input
string
required
The current value of the input field. Should be controlled by parent component state.
onInputChange
(value: string) => void
required
Callback function triggered when the input value changes. Receives the new input value as a string.
onSubmit
() => void
required
Callback function triggered when the user submits the message (via button click or Enter key).
onReset
() => void
required
Callback function triggered when the user clicks the reset/home button.
onInfoClick
() => void
required
Callback function for info button clicks (defined in interface but not currently used in implementation).
isResetDisabled
boolean
required
Whether the reset button should be disabled. Typically true when there are no messages.
isLoading
boolean
required
Whether the chat is currently processing a message. Disables input and buttons during loading.

TypeScript Interface

interface ChatInputProps {
  input: string;
  onInputChange: (value: string) => void;
  onSubmit: () => void;
  onReset: () => void;
  onInfoClick: () => void;
  isResetDisabled: boolean;
  isLoading: boolean;
}

Usage

import { ChatInput } from "@/components/chat-input";
import { useState } from "react";

function ChatApp() {
  const [input, setInput] = useState("");
  const [isLoading, setIsLoading] = useState(false);
  const [messages, setMessages] = useState([]);

  const handleSubmit = async () => {
    if (!input.trim()) return;
    
    setIsLoading(true);
    // Send message logic
    setInput("");
    setIsLoading(false);
  };

  const handleReset = () => {
    setMessages([]);
    setInput("");
  };

  return (
    <ChatInput
      input={input}
      onInputChange={setInput}
      onSubmit={handleSubmit}
      onReset={handleReset}
      onInfoClick={() => {}}
      isResetDisabled={messages.length === 0}
      isLoading={isLoading}
    />
  );
}

Features

Auto-Resize Textarea

  • Automatically expands as content grows
  • Minimum height: 48px
  • Maximum height: 160px
  • Smooth transition when resizing

Keyboard Shortcuts

  • Enter: Submit message
  • Shift + Enter: Insert new line

Visual Feedback

  • Glowing shadow effect on focus
  • Submit button disabled when input is empty or loading
  • Loading state disables all interactions
  • Tooltips on action buttons

Action Buttons

  1. Submit Button (ArrowRight icon)
    • Position: Bottom-right inside textarea
    • Disabled when: input empty or loading
  2. Reset Button (Home icon)
    • Position: Far right inside textarea
    • Disabled when: isResetDisabled is true or loading

Styling

The component uses a dark theme with:
  • Gray-800 background
  • Zinc-700 borders
  • Accent color highlights on focus
  • White glowing shadow effects
  • Responsive padding (sm breakpoint)

Auto-Focus

The component uses the useFocusOnLoad custom hook to automatically focus the textarea when:
  • The component mounts
  • The loading state changes
This ensures a smooth user experience by keeping the input ready for interaction.

ChatHeader

Header with reset functionality

ChatMessage

Displays submitted messages

Source Code

View the source code on GitHub

Build docs developers (and LLMs) love