gluestack-ui logopreview
Docs
Blog
Get Updates
Prompt to React Native
Home
Components
Hooks
Apps
Guides
Home
Overview
IntroductionQuick Start
Getting Started
InstallationTooling SetupVS Code ExtensionsFigma UI KitCLIgluestack-ui-nativewind-utils
Core Concepts
AccessibilityUniversal
Performance
Benchmarks
Theme Configuration
Default TokensCustomizing ThemeDark Mode
Components
All Components
Typography
HeadingrscTextrsc
Layout
BoxrscCenterrscDividerHStackrscVStackrscGridalpha, rsc
Feedback
AlertProgressSpinnerToast
Data Display
BadgeCardrscTablealphaTabsalpha
Forms
ButtonCheckboxDateTimePickeralphaCalendaralphaFormControlInputLinkPressableRadioSelectSliderSwitchTextareaChatAi
Overlay
AlertDialogDrawerLiquid GlassalphaMenuModalPopoverPortalTooltipImage Vieweralpha
Disclosure
ActionsheetAccordionBottomSheetalpha
Media And Icons
AvatarImageIconrsc
Others
FabSkeletonalpha, rsc
Hooks
useBreakPointValue
useMediaQuery
Apps
Dashboard App
Kitchensink App
Todo App
Starter Kit
AppLighter
Guides
Recipes
LinearGradient
Tutorials
Building Ecommerce App
More
Upgrade to v2Upgrade to v3Upgrade to v4Upgrade to v5FAQsReleasesChangelogRoadmapTroubleshootingDiscord FAQs

Chat AI

Build AI chat interfaces with a comprehensive set of components including conversations, messages, attachments, and prompt inputs. Perfect for creating AI-powered chat applications in React & React Native. This is an illustration of Chat AI components. A basic chat interface example. This is just a mock example—features like streaming and image upload do not work here. However, they function properly when using the useChat hook from Vercel with an OpenRouter API key.

Installation

Run the following command:

npx gluestack-ui@alpha add chat-ai

API Reference

To use this component in your project, include the following import statement in your file.
import {
  Conversation,
  ConversationContent,
  ConversationEmptyState,
  ConversationScrollButton,
  ConversationDownload,
  Message,
  MessageContent,
  MessageResponse,
  MessageToolbar,
  MessageAction,
  MessageBranch,
  PromptInput,
  PromptInputProvider,
  PromptInputActionMenu,
  PromptInputActionMenuContent,
  PromptInputActionMenuTrigger,
  usePromptInputAttachments,
  Attachments,
  Attachment,
  AttachmentPreview,
  AttachmentRemove,
} from '@/components/ui/chat-ai';

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

Conversation

The root container for the chat interface. It provides context for the entire conversation.
PropTypeDefaultDescription
children
ReactNode-The content of the conversation.
className
string-Additional CSS classes to apply.

ConversationContent

Displays the list of messages in the conversation.
PropTypeDefaultDescription
messages
Array<UIMessage>-Array of messages to display.
renderItem
ListRenderItem<UIMessage>-Custom render function for messages.
estimatedItemSize
number140Estimated height of each message item.

Message

Represents an individual message in the conversation.
PropTypeDefaultDescription
role
'user' | 'assistant'-The role of the message sender.
index
number-The index of the message in the list.
message
UIMessage-The message data object.
children
ReactNode-The content of the message.
className
string-Additional CSS classes to apply.

MessageContent

Wrapper for the message content with role-based styling.
PropTypeDefaultDescription
children
ReactNode-The content to display.
className
string-Additional CSS classes to apply.

MessageResponse

Renders the message content with markdown support.
PropTypeDefaultDescription
message
UIMessage-The message object containing content and parts.

MessageToolbar

Container for message action buttons.
PropTypeDefaultDescription
children
ReactNode-Action buttons to display.
className
string-Additional CSS classes to apply.

MessageAction

Individual action button for messages.
PropTypeDefaultDescription
onPress
() => void-Callback when action is pressed.
tooltip
string-Tooltip text for the action.
children
ReactNode-The icon or content of the action.

PromptInput

Input area for typing and sending messages.
PropTypeDefaultDescription
children
ReactNode-Additional content (attachments, etc.).
onSubmit
(message: PromptInputMessage) => void-Callback when message is submitted.

PromptInputProvider

Provider component for managing prompt input state.
PropTypeDefaultDescription
children
ReactNode-Child components.

Attachment Components

Components for handling file attachments. Attachments - Container for multiple attachments. Attachment - Individual attachment item. AttachmentPreview - Preview of the attachment (image or icon). AttachmentRemove - Button to remove an attachment.

Usage

Basic Usage

import {
  Conversation,
  ConversationContent,
  Message,
  MessageContent,
  MessageResponse,
  PromptInput,
  PromptInputProvider,
} from '@/components/ui/chat-ai';

function Chat() {
  const [messages, setMessages] = useState([]);

  const handleSubmit = ({ text, files }) => {
    // Handle message submission
    setMessages([...messages, { role: 'user', content: text }]);
  };

  return (
    <Conversation>
      <ConversationContent messages={messages} />
      <PromptInputProvider>
        <PromptInput onSubmit={handleSubmit} />
      </PromptInputProvider>
    </Conversation>
  );
}

With AI SDK

import { useChat } from '@ai-sdk/react';
import { DefaultChatTransport } from 'ai';
import { fetch as expoFetch } from 'expo/fetch';

function AIChat() {
  const { messages, sendMessage } = useChat({
    transport: new DefaultChatTransport({
      fetch: expoFetch,
      api: 'http://localhost:8082/api/chat',
    }),
  });

  const handleSubmit = (message) => {
    sendMessage({
      text: message.text,
      files: message.files,
    });
  };

  return (
    <Conversation>
      <ConversationContent messages={messages} />
      <PromptInputProvider>
        <PromptInput onSubmit={handleSubmit} />
      </PromptInputProvider>
    </Conversation>
  );
}

Accessibility

Keyboard Navigation

  • Tab: Move focus between interactive elements
  • Enter: Submit message or activate buttons
  • Shift + Enter: New line in text input
  • Escape: Close menus or modals

Screen Reader

  • Messages are announced with proper role and labeling
  • Attachment previews have descriptive alt text
  • Action buttons have accessible labels

Focus Management

  • Focus is managed when opening menus
  • Input field maintains focus for continuous typing
  • Keyboard-aware scrolling for chat list

Best Practices

Do's

  • ✅ Use semantic HTML for better accessibility
  • ✅ Provide clear feedback for user actions
  • ✅ Handle loading states gracefully
  • ✅ Validate file types and sizes before upload
  • ✅ Implement proper error handling

Don'ts

  • ❌ Don't store sensitive data in local state
  • ❌ Don't ignore accessibility requirements
  • ❌ Don't forget to handle network errors
  • ❌ Don't allow unlimited file uploads

Related Components

  • Textarea
    - Multi-line text input
  • Button
    - Action buttons
  • Menu
    - Dropdown menus
  • Tooltip
    - Helpful hints
Edit this page on GitHub
Go backTextarea
Up nextAlertDialog
Go backTextarea
Up nextAlertDialog