Dojo NG is being built in the open, one section at a time — follow along on Heptapod.

API REFERENCE · LAYOUT

<dj-split-panel>

Two resizable panes with a draggable divider between them.

Put the panes in the start and end slots. position is the start pane's share of the space, as a percent from 0 to 100. The host needs a size, because the panes fill it: for a horizontal split, give it a height.

Try it in the playground

@dojo-ng/split-panel · v0.2.0

npm install @dojo-ng/split-panel

import "@dojo-ng/split-panel";

Layout

  • orientation="horizontal" (the default) puts the panes side by side with a vertical divider. vertical stacks them with a horizontal divider.
  • The panes always divide in the ratio position : (100 − position).
  • Minimum pane sizes come from CSS, not from properties: set --dj-split-panel-min-start and --dj-split-panel-min-end in any length unit, and dragging stops at that size.
  • The order follows the writing direction, so in a right-to-left page the start pane is on the right with no extra work.
  • The divider bar is drawn by the component. Put custom grip content in the optional divider slot.
  • For three panes, nest a second dj-split-panel inside a slot of the first.

Resizing

  • Drag the divider with a mouse, a trackpad, or touch.
  • Or focus the divider and use the keyboard, so resizing never requires dragging (WCAG 2.5.7): the arrow keys move it by 1 (Shift: by 10), Home moves it to 0, and End to 100. A horizontal split uses Left and Right in the reading direction; a vertical split uses Up and Down.
  • dj-reposition fires when the split settles: once when a drag ends, and once per key press.

Accessibility

  • The divider has role="separator", with aria-valuenow, aria-valuemin, and aria-valuemax tracking position.
  • Its aria-orientation is the divider's own direction, so a horizontal split has a vertical separator.

Navigation

  • With @dojo-ng/history installed with scroll on, Back, Forward and reload put both panes back where the user left them, as they do for the page. The panes scroll inside the shadow root, so the panel registers them itself, as <id>:start and <id>:end.
  • That needs an id on the host, unique on the page and the same each time the view is rendered, so a panel re-created after Back gets its old offsets. Without an id, nothing is registered, and one console warning per page says so.
  • Set no-scroll-restore to leave a panel's panes alone.
  • The package is only read when history is installed; a panel on a page without it is unchanged.

Properties

PropertyAttributeTypeDefault
orientationLayout axis. horizontal = panes side by side (vertical divider); vertical = stacked. orientation reflected "horizontal""vertical" "horizontal"
positionThe start pane's share of the host, as a percent (0–100). position reflected number 50
disabledWhen set, the divider is inert (no drag, no keyboard, not a tab stop). disabled reflected boolean false
noScrollRestoreDon't save and restore the panes' scroll positions with navigation history. no-scroll-restore reflected boolean false

Events

EventDescription
dj-repositiondetail { position }

Slots

startdividerend

CSS parts

Style these with dj-split-panel::part(name).

startenddivider

CSS custom properties

PropertyDefaultDescription
--dj-split-panel-min-start0Minimum size of the start pane (any length).
--dj-split-panel-min-end0Minimum size of the end pane (any length).
--dj-split-panel-divider-width4pxThickness of the divider bar.
--dj-split-panel-divider-colorvar(--dj-color-border)Divider bar color.