Tab group nodes with active tab state
experimental
A tab group holds an ordered list of panes and records which pane is active. Order and active tab are part of the model.
Live example
Expected behavior
Activating or reordering tabs updates activePaneId and the panes array immediately. Moving the last tab out of a group either removes the group or leaves an empty group, depending on the toggle. Arrow keys move between tabs and Ctrl+Shift+PageUp/PageDown reorder the focused tab.
Source
import { createDockModel } from '@warlockcode/warui-core';
const model = createDockModel({
root: {
type: 'split',
id: 'root',
children: [
{ type: 'tabs', id: 'group-a', activePaneId: 'main.ts',
panes: [
{ id: 'main.ts', kind: 'document', title: 'main.ts' },
{ id: 'styles.css', kind: 'document', title: 'styles.css' },
] },
{ type: 'tabs', id: 'group-b', panes: [] },
],
},
}, { allowEmptyGroups: true });
model.on('layoutChange', (event) => console.log(event.reason));
model.activatePane('styles.css');
// Final position in the target group; emits one 'move' event.
model.movePane('main.ts', 'group-b', 0);
import { createDockModel } from '@warlockcode/warui-core';
const model = createDockModel({
root: {
type: 'split',
id: 'root',
children: [
{ type: 'tabs', id: 'group-a', activePaneId: 'main.ts',
panes: [
{ id: 'main.ts', kind: 'document', title: 'main.ts' },
{ id: 'styles.css', kind: 'document', title: 'styles.css' },
] },
{ type: 'tabs', id: 'group-b', panes: [] },
],
},
}, { allowEmptyGroups: true });
model.on('layoutChange', (event) => console.log(event.reason));
model.activatePane('styles.css');
// Final position in the target group; emits one 'move' event.
model.movePane('main.ts', 'group-b', 0);
import { createDockModel } from '@warlockcode/warui-core';
const model = createDockModel({
root: {
type: 'split',
id: 'root',
children: [
{ type: 'tabs', id: 'group-a', activePaneId: 'main.ts',
panes: [
{ id: 'main.ts', kind: 'document', title: 'main.ts' },
{ id: 'styles.css', kind: 'document', title: 'styles.css' },
] },
{ type: 'tabs', id: 'group-b', panes: [] },
],
},
}, { allowEmptyGroups: true });
model.on('layoutChange', (event) => console.log(event.reason));
model.activatePane('styles.css');
// Final position in the target group; emits one 'move' event.
model.movePane('main.ts', 'group-b', 0);
import { createDockModel } from '@warlockcode/warui-core';
const model = createDockModel({
root: {
type: 'split',
id: 'root',
children: [
{ type: 'tabs', id: 'group-a', activePaneId: 'main.ts',
panes: [
{ id: 'main.ts', kind: 'document', title: 'main.ts' },
{ id: 'styles.css', kind: 'document', title: 'styles.css' },
] },
{ type: 'tabs', id: 'group-b', panes: [] },
],
},
}, { allowEmptyGroups: true });
model.on('layoutChange', (event) => console.log(event.reason));
model.activatePane('styles.css');
// Final position in the target group; emits one 'move' event.
model.movePane('main.ts', 'group-b', 0);
// JavaScript module for Blazor interop
import { createDockModel } from '@warlockcode/warui-core';
const model = createDockModel({
root: {
type: 'split',
id: 'root',
children: [
{ type: 'tabs', id: 'group-a', activePaneId: 'main.ts',
panes: [
{ id: 'main.ts', kind: 'document', title: 'main.ts' },
{ id: 'styles.css', kind: 'document', title: 'styles.css' },
] },
{ type: 'tabs', id: 'group-b', panes: [] },
],
},
}, { allowEmptyGroups: true });
model.on('layoutChange', (event) => console.log(event.reason));
model.activatePane('styles.css');
// Final position in the target group; emits one 'move' event.
model.movePane('main.ts', 'group-b', 0);
API reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Node type | type: 'tabs' | — | Leaf container holding panes. |
| Property | panes | DockPane[] | Ordered panes. Duplicate ids inside a group are removed with a warning. |
| Property | activePaneId | string | null | Always a pane of the same group, or null when empty. An invalid value activates the first pane with a warning. |
| Method | activatePane | (paneId: string) => void | Activates a pane and emits layoutChange with reason 'activate'. No-op if already active. |
| Method | movePane | (paneId: string, targetGroupId: string, index: number) => void | Moves a pane, keeping its id, and emits a single layoutChange with reason 'move'. Moving to the same position is a no-op. The previously active pane's neighbour becomes active in the source group. |
| Option | allowEmptyGroups | boolean | When false, a group whose last pane moved out is removed. Default true. |