---
title: "Chat App | Free React & Tailwind Agents Component | Motion UI"
canonical: "https://blacknest.dev/motion/c/agents/chat-app"
github_source: "https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/chat-app.tsx"
install_command: "npx motion-ui-skill add chat-app"
dependencies: ["clsx","lucide-react","motion","react","react-dom","shiki","tailwind-merge"]
category: "agents"
subcategory: "agents"
---

# Chat App

> A complete agent conversation workspace composing navigation, messages, streaming, planning, approvals, tools, code, diffs, generated media, sources, and prompt input.

## Install

```bash
npx motion-ui-skill add chat-app
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `react-dom`
- `shiki`
- `tailwind-merge`

## Usage

```tsx
"use client";

import { Maximize2, Minimize2 } from "lucide-react";
import { useCallback, useEffect, useRef, useState } from "react";
import { ChatAppExample } from "@/components/previews/agents/chat-app-usage";
import { ActionSwapIcon } from "@/components/motion/action-swap";
import { cn } from "@/lib/utils";

export function ChatAppPreview() {
  const [expanded, setExpanded] = useState(false);
  const containerRef = useRef<HTMLDivElement>(null);
  const toggleRef = useRef<HTMLButtonElement>(null);

  useEffect(() => {
    if (!expanded) return;
    const container = containerRef.current;
    if (!container) return;
    const previousOverflow = document.body.style.overflow;
    document.body.style.overflow = "hidden";
    const isolated: Array<{
      element: HTMLElement;
      inert: boolean;
      ariaHidden: string | null;
    }> = [];
    let branch: HTMLElement = container;
    while (branch.parentElement) {
      const parent = branch.parentElement;
      for (const sibling of Array.from(parent.children)) {
        if (sibling === branch || !(sibling instanceof HTMLElement)) continue;
        isolated.push({
          element: sibling,
          inert: sibling.inert,
          ariaHidden: sibling.getAttribute("aria-hidden"),
        });
        sibling.inert = true;
        sibling.setAttribute("aria-hidden", "true");
      }
      if (parent === document.body) break;
      branch = parent;
    }

    const focusableSelector = [
      "a[href]",
      "button:not([disabled])",
      "input:not([disabled])",
      "select:not([disabled])",
      "textarea:not([disabled])",
      "[tabindex]:not([tabindex='-1'])",
    ].join(",");
    const handleKeyDown = (event: KeyboardEvent) => {
      if (event.key === "Escape") {
        event.preventDefault();
        setExpanded(false);
        return;
      }
      if (event.key !== "Tab") return;
      const focusable = Array.from(
        container.querySelectorAll<HTMLElement>(focusableSelector),
      ).filter((element) => !element.inert && element.offsetParent !== null);
      const first = focusable[0];
      const last = focusable.at(-1);
      if (!first || !last) {
        event.preventDefault();
        container.focus();
      } else if (event.shiftKey && document.activeElement === first) {
        event.preventDefault();
        last.focus();
      } else if (!event.shiftKey && document.activeElement === last) {
        event.preventDefault();
        first.focus();
      }
    };
    window.addEventListener("keydown", handleKeyDown);
    requestAnimationFrame(() =>
      toggleRef.current?.focus({ preventScroll: true }),
    );
    return () => {
      document.body.style.overflow = previousOverflow;
      window.removeEventListener("keydown", handleKeyDown);
      for (const { element, inert, ariaHidden } of isolated) {
        element.inert = inert;
        if (ariaHidden === null) element.removeAttribute("aria-hidden");
        else element.setAttribute("aria-hidden", ariaHidden);
      }
      requestAnimationFrame(() =>
        toggleRef.current?.focus({ preventScroll: true }),
      );
    };
  }, [expanded]);

  const toggleExpanded = useCallback(() => {
    setExpanded((current) => !current);
  }, []);

  return (
    <div
      ref={containerRef}
      role="dialog"
      aria-modal={expanded || undefined}
      aria-label="Chat app preview"
      tabIndex={expanded ? -1 : undefined}
      className={cn(
        "relative w-full bg-background px-0 py-2 sm:p-3",
        expanded &&
          "fixed inset-0 z-[100] h-dvh overscroll-contain p-3 sm:p-4",
      )}
    >
      <button
        ref={toggleRef}
        type="button"
        onClick={toggleExpanded}
        aria-label={expanded ? "Exit expanded preview" : "Expand preview"}
        title={expanded ? "Exit expanded preview" : "Expand preview"}
        className="absolute top-5 right-24 z-50 grid size-10 place-items-center rounded-full border border-border/80 bg-background/90 text-muted-foreground backdrop-blur-sm transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
      >
        <ActionSwapIcon
          value={expanded ? "minimize" : "maximize"}
          animation="blur"
        >
          {expanded ? (
            <Minimize2 className="size-4" />
          ) : (
            <Maximize2 className="size-4" />
          )}
        </ActionSwapIcon>
      </button>
      <ChatAppExample className={expanded ? "h-full" : undefined} />
    </div>
  );
}
```

## API Reference

### ChatApp

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `sidebarWidth` | `string` | `17rem` | No | Docked sidebar width as a CSS length. Default `17rem`. |
| `collapseSidebarBelow` | `number` | `600` | No | Shell width in px under which the sidebar folds off-canvas. Ignored while `open` is controlled — the consumer owns the state then. |
| `open` | `boolean` | — | No | — |
| `defaultOpen` | `boolean` | — | No | — |
| `onOpenChange` | `((open: boolean) => void)` | — | No | — |
| `openMobile` | `boolean` | — | No | — |
| `defaultOpenMobile` | `boolean` | — | No | — |
| `onOpenMobileChange` | `((open: boolean) => void)` | — | No | — |
| `style` | `SidebarProviderStyle` | — | No | — |
| `className` | `string` | — | No | — |

## Source Files

- [components/agents/chat-app.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/chat-app.tsx)
- [components/agents/agent-activity/index.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/agent-activity/index.tsx)
- [components/agents/ai-sidebar.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/ai-sidebar.tsx)
- [components/agents/approval-card/index.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/approval-card/index.tsx)
- [components/agents/code-block.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/code-block.tsx)
- [components/agents/file-diff.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/file-diff.tsx)
- [components/agents/image-generation.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/image-generation.tsx)
- [components/agents/loading-states/thinking-shimmer.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/loading-states/thinking-shimmer.tsx)
- [components/agents/message-bubble.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/message-bubble.tsx)
- [components/agents/message-scroller.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/message-scroller.tsx)
- [components/agents/message.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/message.tsx)
- [components/agents/prompt-input.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/prompt-input.tsx)
- [components/agents/streaming-response.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/streaming-response.tsx)
- [components/agents/todo-list.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/todo-list.tsx)
- [components/agents/tool-approval.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/tool-approval.tsx)
- [components/agents/tool-result.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/tool-result.tsx)
- [components/agents/agent-activity/activity-row.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/agent-activity/activity-row.tsx)
- [components/agents/agent-activity/types.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/agent-activity/types.ts)
- [components/agents/agent-code.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/agent-code.tsx)
- [components/agents/agent-disclosure.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/agent-disclosure.tsx)
- [components/agents/approval-card/types.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/approval-card/types.ts)
- [components/agents/citations.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/citations.tsx)
- [components/agents/loading-states/agent-progress.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/loading-states/agent-progress.tsx)
- [components/agents/loading-states/index.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/loading-states/index.ts)
- [components/agents/loading-states/reasoning-text.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/loading-states/reasoning-text.tsx)
- [components/agents/message-context.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/agents/message-context.tsx)
- [components/motion/action-swap-roll.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/action-swap-roll.tsx)
- [components/motion/action-swap.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/action-swap.tsx)
- [components/motion/animated-sidebar.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/animated-sidebar.tsx)
- [components/motion/button/base.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/button/base.tsx)
- [components/motion/button/index.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/button/index.tsx)
- [components/motion/button/magnetic.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/button/magnetic.tsx)
- [components/motion/button/metallic.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/button/metallic.tsx)
- [components/motion/button/stateful.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/button/stateful.tsx)
- [components/motion/checkbox.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/checkbox.tsx)
- [components/motion/input.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/input.tsx)
- [components/motion/loader.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/loader.tsx)
- [components/motion/magnetic.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/magnetic.tsx)
- [components/motion/popover-morph.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/popover-morph.tsx)
- [components/motion/popover-position.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/popover-position.ts)
- [components/motion/preview-rail.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/preview-rail.tsx)
- [components/motion/radio.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/radio.tsx)
- [components/motion/select.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/select.tsx)
- [components/motion/shared-layout-bg.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/shared-layout-bg.tsx)
- [components/motion/text-scramble.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/text-scramble.tsx)
- [components/motion/text-shimmer.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/text-shimmer.tsx)
- [components/previews/agents/chat-app-usage.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/previews/agents/chat-app-usage.tsx)
- [lib/ease.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/ease.ts)
- [lib/favicon.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/favicon.ts)
- [lib/hooks/use-dismiss.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-dismiss.ts)
- [lib/hooks/use-favicon.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-favicon.ts)
- [lib/hooks/use-hover-capable.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-hover-capable.ts)
- [lib/hooks/use-hover-gesture.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-hover-gesture.ts)
- [lib/hooks/use-tap-gesture.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-tap-gesture.ts)
- [lib/hooks/use-touch-capable.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/hooks/use-touch-capable.ts)
- [lib/portal.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/portal.tsx)
- [lib/text-shimmer.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/text-shimmer.ts)
- [lib/touch.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/touch.ts)
- [lib/utils.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/utils.ts)
