# CodeTabs

`CodeTabs` puts equivalent examples in one frame with an integrated tab header.
Each `CodeExample` contains one ordinary fenced MDX block. The filename (or language when no filename is given) sits at the right end of the tab row. Copy, Wrap,
and line-number controls remain inside the code block; line numbers retain
their site-wide setting. Both examples remain in generated Markdown and agent docs.

```shell file="terminal"
echo 'Hello from Dockit'
```

```python
print("Hello from Dockit")
```

## Authoring

Import both components from `@dreamlake/dockit`. Keep blank lines around the
fences so MDX parses them as code; use `shell` for shell examples.

````mdx

```shell file="terminal"
echo 'Hello from Dockit'
```

```python
print("Hello from Dockit")
```

````

`CodeExample.label` names its tab. `CodeTabs` accepts an optional `aria-label`
(default: `Code examples`) to distinguish multiple groups. The first example is
selected initially. Left/Right arrows wrap through tabs; Home/End select the first
or last tab. Selection moves keyboard focus to the active tab, and inactive panels
are hidden from keyboard and accessibility navigation. Each group has unique tab/panel identifiers and, unless linked with `syncKey`,
independent selection.

## Linked tabs

Pass the same `syncKey` to several `CodeTabs` to link them: choosing a tab in
one selects the tab with the same label in every group sharing that key, on
this page and on other pages. The choice persists in localStorage under
`doc:code-tabs:<syncKey>`, so it survives navigation and reloads, and other
open browser tabs follow it. A group without the chosen label keeps its own
selection. Without `syncKey`, each group stays independent.

```shell file="terminal"
echo 'Hello from Dockit'
```

```python
print("Hello from Dockit")
```

```typescript
console.log('Hello from Dockit')
```

```shell file="terminal"
echo 'Goodbye from Dockit'
```

```python
print("Goodbye from Dockit")
```

````mdx

…
…

````

Labels match exactly, so keep them identical across a group (`TypeScript`, not
`TS` in one place). Server-rendered HTML always selects the first tab; a stored
choice is applied while the page hydrates, and immediately on client-side
navigation. Choose a key that names the axis being chosen (for example,
`notes-api-interface`), since every page using that key shares one choice.

Use [CodeBlock](/reference/components/code-block.md) alone for a single example.
No site-specific CSS or replacement code renderer is required.

The compact tab row uses UIKit TabbedContainer with raised file-tab styling on the page background. The active tab shares the code surface, while inactive tabs show a faint outline on hover. Code examples retain their Copy and Wrap buttons and shared line-number setting. Long tab labels scroll horizontally, while long filenames truncate with their full text available on hover. Standalone code blocks keep their filename header.
