> ## 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.

# TabbedLayout – Design

> Tabbed layouts organize related views into selectable tabs.

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-tabbed-layout" screenshot fullWidth>
  ```tsx lines theme={null}
  import { TabbedLayout, Text } from "@servicetitan/carto-react-kit";
  import type { TabbedLayoutTab } from "@servicetitan/carto-react-kit";

  const tabs: TabbedLayoutTab[] = [
    {
      key: "tab-a",
      label: "Tab Name A",
      content: <Text text="Tab A contents." />,
    },
    {
      key: "tab-b",
      label: "Tab Name B",
      content: <Text text="Tab B contents." />,
    },
  ];

  function App() {
    return (
      <div
        style={{
          width: 900,
          height: 420,
          border: "1px solid #ccc",
          overflow: "hidden",
        }}
      >
        <TabbedLayout tabs={tabs} />
      </div>
    );
  }

  export default App;
  ```
</LiveCode>

## Options

TabbedLayout holds one or more tabs and arranges them either as a tab strip or two simultaneously-visible panes.

### Display Modes

<LiveCode example="carto-tabbed-layout-display-modes" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, TabbedLayout, Text } from "@servicetitan/carto-react-kit";
  import type {
    TabbedLayoutMode,
    TabbedLayoutTab,
  } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const tabs: TabbedLayoutTab[] = [
    {
      key: "tab-a",
      label: "Tab Name A",
      content: <Text text="Tab A contents." />,
    },
    {
      key: "tab-b",
      label: "Tab Name B",
      content: <Text text="Tab B contents." />,
    },
  ];

  function Labeled({ label, mode }: { label: string; mode: TabbedLayoutMode }) {
    return (
      <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
        <Text variant="eyebrow" text={label} />
        <div
          style={{
            width: 820,
            height: 220,
            border: "1px solid #ccc",
            overflow: "hidden",
          }}
        >
          <TabbedLayout tabs={tabs} defaultMode={mode} />
        </div>
      </div>
    );
  }

  function App() {
    return (
      <CartoTheme>
        <div style={{ display: "flex", flexDirection: "column", gap: 24 }}>
          <Labeled label="Stacked" mode="stacked" />
          <Labeled label="Vertical Split" mode="vertical-split" />
          <Labeled label="Horizontal Split" mode="horizontal-split" />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

#### Stacked

The classic tabs interaction: a tab strip with one panel visible at a time. Always available, and the mode every layout falls back to below 720px or with anything other than exactly two tabs.

#### Vertical Split

Both panels shown side by side, divided by a vertical rule. Offered only with exactly two tabs, at ≥ 720px.

#### Horizontal Split

Both panels stacked top and bottom, divided by a horizontal rule. Same two-tab, ≥ 720px constraint as Vertical Split.

### Narrow

<LiveCode example="carto-tabbed-layout-narrow" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, TabbedLayout, Text } from "@servicetitan/carto-react-kit";
  import type { TabbedLayoutTab } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const tabs: TabbedLayoutTab[] = [
    {
      key: "tab-a",
      label: "Tab Name A",
      content: <Text text="Tab A contents." />,
    },
    {
      key: "tab-b",
      label: "Tab Name B",
      content: <Text text="Tab B contents." />,
    },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 560,
            height: 160,
            border: "1px solid #ccc",
            overflow: "hidden",
          }}
        >
          <TabbedLayout tabs={tabs} defaultMode="vertical-split" />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

Below 720px — measured on the layout's own width, not the viewport — the layout is forced to Stacked and the mode menu hides, regardless of `defaultMode`. The last chosen mode is remembered and restored once it grows back past the threshold.

### Single Tab

<LiveCode example="carto-tabbed-layout-single-tab" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, TabbedLayout, Text } from "@servicetitan/carto-react-kit";
  import type { TabbedLayoutTab } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const tabs: TabbedLayoutTab[] = [
    {
      key: "preview",
      label: "Preview",
      content: <Text text="Preview contents." />,
    },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 420,
            height: 140,
            padding: 8,
            background: "#e0e0e0",
          }}
        >
          <div style={{ width: "100%", height: "100%", overflow: "hidden" }}>
            <TabbedLayout tabs={tabs} />
          </div>
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

A single tab shows neither a tab strip nor the mode menu — there's nothing to switch between or arrange, so the layout renders just that tab's label heading and content.

## Behavior

The layout adapts to its own measured width and lets the user resize or rearrange its panes.

### Mode Picker

<LiveCode example="carto-tabbed-layout-mode-picker" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, TabbedLayout, Text } from "@servicetitan/carto-react-kit";
  import type { TabbedLayoutTab } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const tabs: TabbedLayoutTab[] = [
    {
      key: "tab-a",
      label: "Tab Name A",
      content: <Text text="Tab A contents." />,
    },
    {
      key: "tab-b",
      label: "Tab Name B",
      content: <Text text="Tab B contents." />,
    },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 900,
            height: 300,
            border: "1px solid #ccc",
            overflow: "hidden",
          }}
        >
          <TabbedLayout tabs={tabs} />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

The top-right options menu lets the user pick a display mode — shown only when a split is currently possible (≥ 720px, exactly two tabs). The current mode carries a check. When the layout is the artifact drawer, a close button joins the same corner and dismisses the drawer via the app surface.

### Split Resize

<LiveCode example="carto-tabbed-layout-split-resize" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, TabbedLayout, Text } from "@servicetitan/carto-react-kit";
  import type { TabbedLayoutTab } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const tabs: TabbedLayoutTab[] = [
    {
      key: "tab-a",
      label: "Tab Name A",
      content: <Text text="Tab A contents." />,
    },
    {
      key: "tab-b",
      label: "Tab Name B",
      content: <Text text="Tab B contents." />,
    },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 820,
            height: 260,
            border: "1px solid #ccc",
            overflow: "hidden",
          }}
        >
          <TabbedLayout tabs={tabs} defaultMode="vertical-split" />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

Drag the separator between the two panes (or focus it and use the arrow keys) to resize them. Both panes are clamped to a per-axis minimum, so neither can be dragged small enough to lose its heading and all its content.

### Overflow Handling

<LiveCode example="carto-tabbed-layout-overflow-handling" screenshot fullWidth>
  ```tsx lines theme={null}
  import { CartoTheme, TabbedLayout, Text } from "@servicetitan/carto-react-kit";
  import type { TabbedLayoutTab } from "@servicetitan/carto-react-kit";
  import "@servicetitan/carto-react-kit/styles.css";

  const tabs: TabbedLayoutTab[] = [
    {
      key: "doc",
      label: "Document",
      content: (
        <>
          {Array.from({ length: 12 }, (_, i) => (
            <p key={i} style={{ marginTop: i === 0 ? 0 : undefined }}>
              Paragraph {i + 1}. Overflowing content scrolls within the panel's
              padding, not flush to its edge.
            </p>
          ))}
        </>
      ),
    },
    { key: "notes", label: "Notes", content: <Text text="Short notes." /> },
  ];

  function App() {
    return (
      <CartoTheme>
        <div
          style={{
            width: 900,
            height: 320,
            border: "1px solid #ccc",
            overflow: "hidden",
          }}
        >
          <TabbedLayout tabs={tabs} defaultMode="vertical-split" />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

Content taller than a panel scrolls inside its padding — the scroll region is inset, so the scrollbar and the scrolled content stop at the padded edge rather than running flush to the panel's border.

## Keyboard Interaction

Users can switch tabs, resize a split, and choose a display mode using standard keyboard controls.

| Key                      | Description                                          |
| ------------------------ | ---------------------------------------------------- |
| Tab                      | Moves focus among the tab strip, panel, and controls |
| Arrow Left / Arrow Right | Moves focus to the previous/next tab (Stacked)       |
| Arrow keys               | Resizes the split when the separator is focused      |
| Enter / Space            | Activates the focused tab or control                 |
| Escape                   | Closes the layout options menu                       |

## Patterns that use this component

* [Agentic Experience Shell](/docs/kits/ai-kit/patterns/agentic-experience-shell) — Organizes multiple related views within the supporting workspace
