> ## Documentation Index
> Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ChatHistory – Design

> Chat history lists prior conversations for navigation and resume.

export const LiveCode = ({children, customHeight, clickToLoad, example, fullWidth, fullHeight, hideCodeInLiveCode, screenshot, screenshotOnly, showCode: showCodeProp}) => {
  const SCREENSHOTS_BASE = "https://servicetitan.github.io/anvil2-docs-live-code/screenshots";
  const STACKBLITZ_BASE = "https://stackblitz.com/github/servicetitan/anvil2-docs-live-code/tree/main/examples";
  const [showCodeBlock, setShowCodeBlock] = useState(showCodeProp ?? false);
  const [isLocalOverride, setIsLocalOverride] = useState(false);
  useEffect(() => {
    const examplePath = `/images/live-code-screenshots-tmp/${example}.png`;
    fetch(examplePath, {
      method: "HEAD"
    }).then(r => {
      if (r.ok) setIsLocalOverride(true);
    }).catch(() => {});
  }, [example]);
  const screenshotBase = isLocalOverride ? "/images/live-code-screenshots-tmp" : SCREENSHOTS_BASE;
  if (screenshotOnly) {
    return <Frame className="flex flex-col">
        <div className="flex dark:hidden" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined,
      background: "#FFFFFF"
    }}>
          <img srcset={`${screenshotBase}/${example}.png, ${screenshotBase}/${example}-2x.png 2x`} src={`${screenshotBase}/${example}.png`} alt={example} noZoom />
        </div>
        <div className="hidden dark:flex" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined,
      background: "#141414"
    }}>
          <img srcset={`${screenshotBase}/${example}-dark.png, ${screenshotBase}/${example}-dark-2x.png 2x`} src={`${screenshotBase}/${example}-dark.png`} alt={example} noZoom />
        </div>
      </Frame>;
  }
  if (screenshot) {
    return <Frame className="flex flex-col -mb-2">
        <div className="flex dark:hidden bg-white dark:bg-codeblock border border-gray-950/10 dark:border-white/10 dark:twoslash-dark rounded-2xl overflow-hidden" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined
    }}>
          <img srcset={`${screenshotBase}/${example}.png, ${screenshotBase}/${example}-2x.png 2x`} src={`${screenshotBase}/${example}.png`} alt={example} noZoom />
        </div>

        <div className="hidden dark:flex bg-white dark:bg-codeblock border border-gray-950/10 dark:border-white/10 dark:twoslash-dark rounded-2xl overflow-hidden" style={{
      background: "#141414",
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined
    }}>
          <img srcset={`${screenshotBase}/${example}-dark.png, ${screenshotBase}/${example}-dark-2x.png 2x`} src={`${screenshotBase}/${example}-dark.png`} alt={example} noZoom />
        </div>

        <div className="flex justify-end items-center text-xs py-2 px-1 gap-4">
          {!showCodeProp ? <button className="inline-flex justify-end items-center text-gray-700 dark:text-gray-50 hover:text-blue-500 dark:hover:text-blue-300 transition-colors group self-end gap-1 cursor-pointer" onClick={() => setShowCodeBlock(!showCodeBlock)} style={{
      appearance: "none"
    }}>
              <Icon icon="code" size="12px" className="group-hover:bg-blue-500 dark:group-hover:bg-blue-300" />
              <span>{showCodeBlock ? "Hide code" : "Show code"}</span>
            </button> : null}

          <a className="inline-flex justify-end items-center hover:text-blue-500 dark:hover:text-blue-300 transition-colors group self-end gap-1" href={`${STACKBLITZ_BASE}/${example}?file=src/App.tsx`} target="_blank" rel="noreferrer">
            <Icon icon="bolt" size="12px" className="group-hover:bg-blue-500 dark:group-hover:bg-blue-300" />
            <span>StackBlitz demo</span>
          </a>
        </div>

        <div className="grid transition-[grid-template-rows] duration-300 ease-in-out overflow-auto overflow-y-hidden overflow-x-auto" style={showCodeBlock ? {
      gridTemplateRows: "1fr"
    } : {
      gridTemplateRows: "0fr"
    }}>
          <div style={{
      minHeight: 0,
      overflowX: "auto",
      overflowY: "hidden",
      marginBlockStart: "-1.25rem",
      marginBlockEnd: "-1.5rem"
    }}>
            {children}
          </div>
        </div>
      </Frame>;
  } else {
    return <div style={{
      display: "flex",
      width: fullWidth ? "100%" : "50%",
      minHeight: customHeight ? customHeight : "316px",
      resize: "vertical",
      overflow: "auto"
    }}>
        <iframe title={example} style={{
      flex: 1,
      width: fullWidth ? "100%" : "50%",
      minHeight: customHeight ? customHeight : "316px"
    }} src={`${STACKBLITZ_BASE}/${example}?embed=1&hideNavigation=1&hideExplorer=1&terminalHeight=0&file=src/App.tsx${clickToLoad ? "&ctl=1" : ""}${hideCodeInLiveCode ? "&view=preview" : ""}`} allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" />
      </div>;
  }
};

export const CodePreviewPlaceholder = ({double, fullWidth}) => {
  const single = <div style={{
    width: fullWidth ? "100%" : "50%",
    borderRadius: "1rem",
    display: "flex",
    padding: "1rem",
    flexDirection: "column",
    gap: "0.5rem",
    height: "10rem",
    marginBlockEnd: "1rem"
  }} className="border-width-default border-color-subdued">
      <div className="bg-strong border-radius-large" style={{
    width: "100%",
    flexGrow: "1"
  }} />
      <div className="bg-strong border-radius-large" style={{
    width: "100%",
    flexGrow: "1"
  }} />
    </div>;
  return double ? <div style={{
    display: "flex",
    gap: "1rem"
  }}>
      {single}
      {single}
    </div> : single;
};

<LiveCode example="carto-chat-history" screenshot fullWidth>
  ```tsx lines theme={null}
  import { ChatHistory } from "@servicetitan/carto-react-kit";
  import type { ChatHistoryItem } from "@servicetitan/carto-react-kit";

  const items: ChatHistoryItem[] = [
    { id: "q3", label: "Q3 planning notes", subtitle: "35 mins" },
    {
      id: "invoice",
      label: "Invoice discrepancy follow-up",
      subtitle: "2 hours",
    },
    { id: "customer", label: "Customer churn analysis", subtitle: "Yesterday" },
  ];

  function App() {
    return (
      <div
        style={{
          width: 240,
          height: 420,
          background: "var(--carto-color-background-surface, #f5f5f5)",
          borderRadius: 8,
          overflow: "hidden",
        }}
      >
        <ChatHistory items={items} defaultSelectedKeys={["q3"]} />
      </div>
    );
  }

  export default App;
  ```
</LiveCode>

## Options

ChatHistory renders a typed `items` array — each chat carries a required label and timestamp, and can flag itself as unread.

### Selected State

<LiveCode example="carto-chat-history-selected-state" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, ChatHistory } from "@servicetitan/carto-react-kit";
  import type { ChatHistoryItem } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const items: ChatHistoryItem[] = [
    { id: "q3", label: "Q3 planning notes", subtitle: "35 mins" },
    {
      id: "invoice",
      label: "Invoice discrepancy follow-up",
      subtitle: "2 hours",
    },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 240,
            height: 220,
            background: "var(--carto-color-background-surface, #f5f5f5)",
            borderRadius: 8,
            overflow: "hidden",
          }}
        >
          <ChatHistory items={items} defaultSelectedKeys={["q3"]} />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

Selection is locked to single — at most one chat is ever active. The selected row keeps a persistent tint and bolds its title; drive it with `selectedKeys` / `onSelectionChange` (controlled) or `defaultSelectedKeys` (uncontrolled), the same way you would a [Menu](/docs/kits/ai-kit/components/menu/design).

### Unread

<LiveCode example="carto-chat-history-unread" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, ChatHistory } from "@servicetitan/carto-react-kit";
  import type { ChatHistoryItem } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const items: ChatHistoryItem[] = [
    {
      id: "auth",
      label: "Refactoring the auth flow",
      subtitle: "Just now",
      unread: true,
    },
    { id: "q3", label: "Q3 planning notes", subtitle: "35 mins", unread: true },
    { id: "karaoke", label: "Karaoke track separation", subtitle: "Yesterday" },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 240,
            height: 220,
            background: "var(--carto-color-background-surface, #f5f5f5)",
            borderRadius: 8,
            overflow: "hidden",
          }}
        >
          <ChatHistory items={items} />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

Set `unread` on a chat to render a dot at the end of its title row (announced as "Unread" to assistive tech). Unread is independent of selection — a chat can be both unread and active.

### Time stamp

<LiveCode example="carto-chat-history-timestamp" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, ChatHistory } from "@servicetitan/carto-react-kit";
  import type { ChatHistoryItem } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  // `subtitle` is rendered verbatim — the consumer owns any relative-time
  // formatting. These four rows show the range a stamp typically takes: a
  // relative duration, a clock time, a day name, and an absolute date.
  const items: ChatHistoryItem[] = [
    { id: "auth", label: "Refactoring the auth flow", subtitle: "35 mins" },
    { id: "karaoke", label: "Karaoke track separation", subtitle: "10:40am" },
    {
      id: "onboarding",
      label: "Rewrite the onboarding email",
      subtitle: "Yesterday",
    },
    { id: "schema", label: "Postgres schema migration plan", subtitle: "Mar 14" },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 240,
            height: 370,
            background: "var(--carto-color-background-surface, #f5f5f5)",
            borderRadius: 8,
            overflow: "hidden",
          }}
        >
          <ChatHistory items={items} />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

`subtitle` is rendered verbatim — Carto doesn't compute relative time. Pass whatever stamp fits the moment: a relative duration, a clock time, a day name, or an absolute date. The consumer owns the formatting and any policy for when it changes.

## Behavior

Rows respond to the standard interaction states and truncate or scroll rather than reflow the rail.

### Visual States

<LiveCode example="carto-chat-history-visual-states" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, ChatHistory } from "@servicetitan/carto-react-kit";
  import type { ChatHistoryItem } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const items: ChatHistoryItem[] = [
    { id: "default", label: "Default", subtitle: "Just now" },
    { id: "hover", label: "Hover target", subtitle: "35 mins" },
    { id: "focus", label: "Focus target", subtitle: "10:40am" },
    { id: "disabled", label: "Disabled", subtitle: "Yesterday" },
    { id: "selected", label: "Selected", subtitle: "Friday" },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 240,
            height: 460,
            background: "var(--carto-color-background-surface, #f5f5f5)",
            borderRadius: 8,
            overflow: "hidden",
          }}
        >
          <ChatHistory
            items={items}
            defaultSelectedKeys={["selected"]}
            disabledKeys={["disabled"]}
          />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

Unselected rows stay neutral — transparent at rest, with a subtle fill on hover and press. The selected row keeps that fill persistently. Keyboard focus shows the ring only, and a disabled chat (via `disabledKeys`) can't be focused, selected, or activated.

### Truncation

<LiveCode example="carto-chat-history-truncation" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, ChatHistory } from "@servicetitan/carto-react-kit";
  import type { ChatHistoryItem } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const items: ChatHistoryItem[] = [
    {
      id: "long",
      label: "A conversation title long enough to overflow the rail width",
      subtitle: "An unread stamp long enough to overflow the rail width too",
    },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 240,
            height: 140,
            background: "var(--carto-color-background-surface, #f5f5f5)",
            borderRadius: 8,
            overflow: "hidden",
          }}
        >
          <ChatHistory items={items} />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

A title or subtitle longer than the rail's width truncates to a single line with a trailing ellipsis — the row never wraps or grows taller.

### Overflow

<LiveCode example="carto-chat-history-overflow" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, ChatHistory } from "@servicetitan/carto-react-kit";
  import type { ChatHistoryItem } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const items: ChatHistoryItem[] = [
    { id: "auth", label: "Refactoring the auth flow", subtitle: "Just now" },
    { id: "q3", label: "Q3 planning notes", subtitle: "35 mins" },
    { id: "karaoke", label: "Karaoke track separation", subtitle: "10:40am" },
    {
      id: "onboarding",
      label: "Rewrite the onboarding email",
      subtitle: "Yesterday",
    },
    {
      id: "schema",
      label: "Postgres schema migration plan",
      subtitle: "Yesterday",
    },
    { id: "pricing", label: "Pricing page copy review", subtitle: "Friday" },
    { id: "incident", label: "Incident postmortem draft", subtitle: "Mar 14" },
    { id: "roadmap", label: "2027 roadmap brainstorm", subtitle: "Mar 12" },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 240,
            height: 280,
            background: "var(--carto-color-background-surface, #f5f5f5)",
            borderRadius: 8,
            overflow: "hidden",
          }}
        >
          <ChatHistory items={items} defaultSelectedKeys={["karaoke"]} />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

A history longer than the rail's height scrolls within it; the "New Chat" button stays pinned above the list.

## Keyboard Interaction

Users can navigate and select chats using standard keyboard controls.

| Key                   | Description                                                |
| --------------------- | ---------------------------------------------------------- |
| Tab                   | Moves focus into or out of the list                        |
| Arrow Up / Arrow Down | Moves focus to the previous/next chat                      |
| Enter / Space         | Selects the focused chat                                   |
| Type-ahead            | Jumps focus to the next chat matching the typed characters |

## Patterns that use this component

* [Agentic Experience Shell](/docs/kits/ai-kit/patterns/agentic-experience-shell) — Provides access to previous conversations
