Skip to content

TabStrip ​

The tabs of the open documents. The strip scrolls sideways, keeps the active tab in view, and draws close buttons, pins, unsaved marks and attention marks. For navigation sections of a view, use Tabs.

tsx
import { ContextMenu, DocumentTab, Icon, TabStrip, type TabStripItem } from '@adecore/ui';
import { FileText } from 'lucide-react';
import { useState } from 'react';

export default function TabStripDemo() {
    const [items, setItems] = useState<TabStripItem[]>([
        { id: 'readme', label: 'README.md', pinned: true },
        { id: 'index', label: 'index.ts', unsaved: true },
        { id: 'theme', label: 'theme.css' }
    ]);
    const [value, setValue] = useState<string | null>('index');

    return (
        <div className="h-10 w-full overflow-hidden rounded-lg border border-border bg-surface">
            <TabStrip
                items={items.map((item) => ({ ...item, icon: <Icon icon={FileText} size={14} /> }))}
                renderTab={(item) => (
                    <ContextMenu.Root>
                        <ContextMenu.Trigger render={<DocumentTab item={item} />} />
                        <ContextMenu.Popup>
                            <ContextMenu.Item
                                onClick={() =>
                                    setItems(items.map((candidate) => (candidate.id === item.id ? { ...candidate, pinned: !candidate.pinned } : candidate)))
                                }
                            >
                                {item.pinned ? 'Unpin tab' : 'Pin tab'}
                            </ContextMenu.Item>
                        </ContextMenu.Popup>
                    </ContextMenu.Root>
                )}
                value={value}
                onValueChange={setValue}
                onDoubleClick={(id) => setItems(items.map((item) => (item.id === id ? { ...item, pinned: !item.pinned } : item)))}
                onClose={(id) => {
                    const next = items.filter((item) => item.id !== id);
                    setItems(next);

                    if (value === id) {
                        setValue(next[0]?.id ?? null);
                    }
                }}
            />
        </div>
    );
}

TabStripProps requires items, value and onValueChange. A TabStripItem has an id and a label, and optionally hint, icon, detail, attention, unsaved, pinned and closable. tabId and panelId tie a tab to a panel the app draws.

When the active tab changes, the strip scrolls it fully into view. Once a person scrolls the strip, it keeps their position until the active tab changes again.

focused (default true) draws the active underline in the accent. The active tab always shows its close button, the others on hover or focus. closable: false hides it. The app acts in onClose(id), onDoubleClick(id, event) and onContextMenu(id, event).

pressToClose closes a tab on a middle click or a Shift-click. Pinned tabs and tabs without a close button stay open.

onDragStart(id, event) makes the tabs draggable; clear drag state in onDragEnd(event). onTabDragOver(index, event) and onTabDrop(index, event) report the gap nearest the pointer, counted in the order before the drag, dragged tab included. Call preventDefault() in dragover to accept a drop. insertAt draws a 2 pixel line at a gap. Drag MIME types and payloads are the app's. A SplitView handles moving tabs between panes itself.

For a tab whose details come from hooks, return a DocumentTab from renderTab(item). DocumentTabProps takes item, the props of a <span>, className, ref and render. Its own onClose(), onDoubleClick(id, event), onDragStart(id, event) and onDragEnd(event) replace the strip's. closeShortcut adds a key to the close button's tooltip. unsaved is a boolean, or the text a screen reader hears instead. For a context menu, render the menu trigger as the tab with render={<DocumentTab item={item} />}.

The strip also takes the props of a <div>, className, ref and render. Give it a height.

Licenses and third-party notices are listed in each package.