import { KbqSplitterModule } from '@koobiq/components/splitter';

KbqSplitter

componentCopy link to KbqSplitter

Splits an area into panels the user can resize by dragging the separators between them.

Panels must be direct children of the splitter — a wrapper element around them hides them from the group.

Example
<kbq-splitter>
    <kbq-splitter-panel [minSize]="100">…</kbq-splitter-panel>
    <kbq-splitter-panel>…</kbq-splitter-panel>
</kbq-splitter>
@Component({ selector: 'kbq-splitter', exportAs: 'kbqSplitter' })
class KbqSplitter implements KbqSplitterGroup {
    readonly orientation = input<KbqSplitterOrientation>('horizontal');
    readonly appearance = input<KbqSplitterAppearance>(
        this.options.appearance
    );
    readonly disabled = input<boolean>(false);
    readonly layout = model<number[] | null>(null);
}
orientationinputCopy link to orientationKbqSplitterOrientation

Direction the panels are laid out in.

appearanceinputCopy link to appearanceKbqSplitterAppearance

How the separators are drawn. Defaults to the app-wide KBQ_SPLITTER_OPTIONS.

disabledinputCopy link to disabledboolean

Whether the panels can be resized at all.

layoutmodelCopy link to layoutnumber[] | null

Sizes of the panels as percentages of the splitter, in panel order.

Two-way and, while null, derived from what the panels declare — so a host reads it to persist a layout, writes it to restore one, and shares the same signal between two splitters to keep their panels the same width. Setting it back to null returns the panels to their declared sizes.

KbqSplitterPanel

componentCopy link to KbqSplitterPanel

A resizable region of a KbqSplitter.

Every panel but the last renders the separator that follows it, so the separator sits between the two panels it resizes in the tab order as well as on screen.

@Component({ selector: 'kbq-splitter-panel', exportAs: 'kbqSplitterPanel' })
class KbqSplitterPanel implements KbqSplitterPanelRef {
    readonly id = input<string>(
        inject(_IdGenerator).getId('kbq-splitter-panel-')
    );
    readonly size = input<KbqSplitterSize | undefined>();
    readonly minSize = input<KbqSplitterSize | undefined>();
    readonly maxSize = input<KbqSplitterSize | undefined>();
    readonly snapSizes = input<readonly KbqSplitterSize[]>([]);
    readonly snapTolerance = input<number>(this.options.snapTolerance);
    readonly collapsible = input<boolean>(false);
    readonly collapsedSize = input<KbqSplitterSize>(0);
    readonly collapsed = model<boolean>(false);
    readonly separatorAriaLabel = input<string | undefined>();
}
idinputCopy link to idstring

Identifies the panel to the aria-controls of its own separator, and gives a host something to point aria-labelledby or a fragment link at. Generated when omitted.

sizeinputCopy link to sizeKbqSplitterSize | undefined

Size the panel starts at, in pixels (240, '240px'), as a share of the splitter ('30%') or as a share of the viewport ('30vw', '30vh'). Panels that leave it unset share whatever the sized ones did not claim.

minSizeinputCopy link to minSizeKbqSplitterSize | undefined

Smallest size the panel may be dragged to. Defaults to 0.

maxSizeinputCopy link to maxSizeKbqSplitterSize | undefined

Largest size the panel may be dragged to. Unbounded when omitted.

snapSizesinputCopy link to snapSizesreadonly KbqSplitterSize[]

Sizes a drag is pulled onto when it is released near one. minSize and maxSize become snap points too as soon as either panel around a separator declares any snap size.

The layout the panels start at settles onto them as well, so a splitter is never handed to the user sitting between two of its own snap points.

snapToleranceinputCopy link to snapTolerancenumber

How close to one of this panel's snapSizes a drag has to be released for it to be pulled in, in pixels. Raise it to make the snap points reach further — past half the gap between two of them the panel can only ever land on a snap size.

Defaults to the app-wide KBQ_SPLITTER_OPTIONS.

collapsibleinputCopy link to collapsibleboolean

Whether dragging the panel past half of its minSize collapses it to collapsedSize instead of stopping at the minimum.

collapsedSizeinputCopy link to collapsedSizeKbqSplitterSize

Size the panel takes while collapsed. 0 — the default — hides it completely.

collapsedmodelCopy link to collapsedboolean

Whether the panel is collapsed. Two-way, so a host can collapse and restore the panel itself — which is the only way back for a panel whose collapsedSize is 0 and which therefore has no separator to grab.

separatorAriaLabelinputCopy link to separatorAriaLabelstring | undefined

Accessible name of the separator that follows the panel; falls back to the localized default.

kbqSplitterOptionsProvider

functionCopy link to kbqSplitterOptionsProvider

Overrides the default splitter options within the given injector scope — the whole application from bootstrapApplication, or one subtree from the providers of a component or a route.

function kbqSplitterOptionsProvider(
    options: Partial<KbqSplitterOptions>
): Provider;

resizeSplitterSizesAt

functionCopy link to resizeSplitterSizesAt

Moves the boundary that follows index by delta pixels and returns the new sizes.

The panels on one side of the boundary take the delta and the ones on the other side give it up, each walking outwards from the boundary: a panel sitting at its limit hands the remainder to the next one instead of stopping the drag. Walking outwards on the taking side too is what keeps a boundary reachable when the panel right beside it is pinned — otherwise a neighbour at its maximum would freeze a boundary that the panels further out could still move, and the drag would do nothing at all.

function resizeSplitterSizesAt(
    sizes: readonly number[],
    index: number,
    delta: number,
    min: readonly number[],
    max: readonly number[]
): number[];

KbqSplitterAppearance

typeCopy link to KbqSplitterAppearance

How a splitter draws its separators.

  • divider — a line between the panels, the default.
  • transparent — nothing until the pointer reaches the separator, which then gives itself away by the cursor.
  • handle — a grip centred on the boundary.
type KbqSplitterAppearance = 'divider' | 'transparent' | 'handle';

KbqSplitterOptions

typeCopy link to KbqSplitterOptions

Settings a whole application shares, rather than something a single splitter decides.

Only what a product picks once belongs here: how its separators look, and how far a snap size reaches. The sizes and limits of the panels are a property of one layout and stay on the panels themselves.

type KbqSplitterOptions = {
    appearance: KbqSplitterAppearance;
    snapTolerance: number;
};
appearanceCopy link to appearanceKbqSplitterAppearance

How the separators are drawn.

snapToleranceCopy link to snapTolerancenumber

How close to a snap size a drag has to be released for it to be pulled in, in pixels.

KbqSplitterOrientation

typeCopy link to KbqSplitterOrientation

Direction the panels of a splitter are laid out in.

type KbqSplitterOrientation = 'horizontal' | 'vertical';

KbqSplitterSize

typeCopy link to KbqSplitterSize

Size of a splitter panel: a number of pixels, a <number>px string, a <number>% share of the splitter's own size along the resize axis, or a <number>vw / <number>vh share of the viewport's width / height. A size in any other unit is ignored.

type KbqSplitterSize = number | string;

KbqSplitterSnapPoint

typeCopy link to KbqSplitterSnapPoint

A size a drag is pulled onto, with the distance the release has to be within for the pull to happen.

type KbqSplitterSnapPoint = {
    size: number;
    tolerance: number;
};

KBQ_SPLITTER_OPTIONS

constCopy link to KBQ_SPLITTER_OPTIONS

Injection token holding the current KbqSplitterOptions.

const KBQ_SPLITTER_OPTIONS: InjectionToken<KbqSplitterOptions>;
Suggestions for improvement
If you found a mistake or want to improve the article, create an issue on GitHub.