Split
<et2-split> | Et2Split
et2-split puts two panels side by side with a draggable divider between them. It is what sits
between a list and a detail view, or between a tree and its contents.
It takes exactly two children, one in the start slot and one in the end slot. In a
template you can leave the slots off - the first two children are assigned to start and
end automatically when the template is parsed - but in hand-written HTML you have to name them
yourself.
A splitter is height: 100%, so it is as tall as whatever contains it. In a container with no
height it collapses to a few pixels and looks like nothing rendered. Give it, or its parent, a height.
Examples
Two panels
position is the divider’s distance from the start edge, as a percentage.
<div style="height: 10em">
<et2-split position="30">
<et2-box slot="start">
<et2-description value="Start panel"></et2-description>
</et2-box>
<et2-box slot="end">
<et2-description value="End panel - drag the divider"></et2-description>
</et2-box>
</et2-split>
</div>
Stacking instead of side by side
vertical stacks the panels, with a horizontal divider between them.
<div style="height: 12em">
<et2-split vertical position="40">
<et2-box slot="start">
<et2-description value="Top"></et2-description>
</et2-box>
<et2-box slot="end">
<et2-description value="Bottom"></et2-description>
</et2-box>
</et2-split>
</div>
The older orientation attribute does the same thing and is still accepted, but it names the
divider rather than the panels, so its values read backwards: orientation="h" means a
horizontal divider, which is vertical above. Prefer vertical in new templates.
Docking
Set primary to say which panel keeps its size when the splitter itself is resized. It also
enables docking: double-click the divider to collapse the primary panel, double-click again to bring it back
to where it was. dock(), undock(), toggleDock() and
isDocked() do the same from javascript.
<div style="height: 10em">
<et2-split id="split-dock-example" primary="start" position="30">
<et2-box slot="start">
<et2-description value="Double-click the divider"></et2-description>
</et2-box>
<et2-box slot="end">
<et2-description value="or use the button below"></et2-description>
</et2-box>
</et2-split>
</div>
<et2-button id="split-dock-button" label="Toggle dock"></et2-button>
<script>
const split = document.getElementById("split-dock-example");
document.getElementById("split-dock-button").addEventListener("click", () =>
{
customElements.whenDefined("et2-split")
.then(() => split.updateComplete)
.then(() => split.toggleDock());
});
</script>
Without primary there is nothing to dock, so double-clicking the divider does nothing.
Limits and snapping
--min and --max bound how far the divider can travel. snap lists
positions it should snap to, and snapThreshold how close it has to get first.
<div style="height: 10em">
<et2-split style="--min: 20%; --max: 80%" snap="25% 50% 75%" snap-threshold="20">
<et2-box slot="start">
<et2-description value="Snaps at 25, 50 and 75%"></et2-description>
</et2-box>
<et2-box slot="end">
<et2-description value="and stops at 20 / 80%"></et2-description>
</et2-box>
</et2-split>
</div>
Reacting to a resize
sl-reposition fires as the divider moves. Read position for the new percentage.
position: 50
<div style="height: 8em">
<et2-split id="split-event-example">
<et2-box slot="start"><et2-description value="Drag me"></et2-description></et2-box>
<et2-box slot="end"><et2-description value=""></et2-description></et2-box>
</et2-split>
</div>
<p>position: <span id="split-event-output">50</span></p>
<script>
const split = document.getElementById("split-event-example");
const out = document.getElementById("split-event-output");
split.addEventListener("sl-reposition", () => {out.textContent = Math.round(split.position);});
</script>
Widgets that size themselves by hand - a nextmatch, anything implementing et2_IResizeable - are
told to resize automatically after the drag ends, so they do not need their own listener.
Remembering the position
A splitter with an id saves where the user left the divider as a preference of the current
application, under splitter-size-<id>, and loads it again the next time the template
runs. Drop the id and the position resets to 50% on every load.
This needs a logged-in session, so there is no live example for it - it is nothing more than adding the
id:
<et2-split id="splitter" primary="start">
<nextmatch id="nm" template="myapp.index.rows"/>
<et2-template id="myapp.detail"/>
</et2-split>
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
position
|
The current position of the divider from the primary panel’s edge as a percentage 0–100. Defaults to 50% of the container’s initial size |
number
|
- | |
primary
|
If no primary panel is designated, both panels will resize proportionally and docking is disabled “start” | “end” | undefined |
string
|
- | |
orientation
|
Legacy orientation “v” | “h”
use vertical=true|false instead |
- | - |
Learn more about attributes and properties.
Inherited properties (22)
Et2Widget
| Name | Description |
|---|---|
accesskey |
Accesskey provides a hint for generating a keyboard shortcut for the current element. The attribute value must consist of a single printable character. |
actions |
Set Actions on the widget Each action is defined as an object: move: { type: “drop”, acceptedTypes: “mail”, icon: “move”, caption: “Move to” onExecute: javascript:mail_move” } This will turn the widget into a drop target for “mail” drag types. When “mail” drag types are dropped, the global function mail_move(egwAction action, egwActionObject sender) will be called. The ID of the dragged “mail” will be in sender.id, some information about the sender will be in sender.context. The etemplate2 widget involved can typically be found in action.parent.data.widget, so your handler can operate in the widget context easily. The location varies depending on your action though. It might be action.parent.parent.data.widget To customise how the actions are handled for a particular widget, override _link_actions(). It handles the more widget-specific parts. |
align |
Used by Et2Box to determine alignment. Allowed values are left, right |
class |
CSS Class. This class is applied to the outside, on the web component itself. Due to how WebComponents work, this might not change anything inside the component. |
data |
Set the dataset from a CSV |
deferredProperties |
Any attribute that refers to row content cannot be resolved immediately, but some like booleans cannot stay a string because it’s a boolean attribute. We store them for later, and parse when they’re fully in their row. If you are creating a widget that can go in a nextmatch row, and it has boolean attributes that can change for each row, add those attributes into deferredProperties |
disabled |
Defines whether this widget is visibly disabled. The widget is still visible, but clearly cannot be interacted with. Widgets disabled in the template will not return a value to the application code, even if re-enabled via javascript before submitting. To allow a disabled widget to be re-enabled and return a value, disable via javascript in the app’s et2_ready() instead of an attribute in the template file. |
dom_id |
Get the actual DOM ID, which has been prefixed to make sure it’s unique. |
hidden |
The widget is not visible. As far as the user is concerned, the widget does not exist. Widgets hidden with an attribute in the template may not be created in the DOM, and will not return a value. Widgets can be hidden after creation, and they may return a value if hidden this way. |
id |
Get the ID of the widget |
label |
The label of the widget This is usually displayed in some way. It’s also important for accessability. This is defined in the parent somewhere, and re-defining it causes labels to disappear |
noLang |
Disable any translations for the widget |
parentId |
Parent is different than what is specified in the template / hierarchy. Widget ID of another node to insert this node into instead of the normal location |
statustext |
Tooltip which is shown for this element on hover |
styles |
WebComponent * |
options |
Get property-values as object |
supportedWidgetClasses |
et2_widget compatability |
SlSplitPanel (Shoelace)
| Name | Description |
|---|---|
positionInPixels |
The current position of the divider from the primary panel’s edge in pixels. |
snap |
One or more space-separated values at which the divider should snap. Values can be in pixels or
percentages, e.g. "100px 50%".
|
snapThreshold |
How close the divider must be to a snap point until snapping occurs. |
vertical |
Draws the split panel in a vertical orientation with the start and end panels stacked. |
LitElement
| Name | Description |
|---|---|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Methods
| Name | Description | Arguments |
|---|---|---|
handlePositionChange()
|
Override parent to avoid resizing when not visible, as that breaks size calculations | - |
handleResize()
|
Override parent to avoid resizing when not visible, as that breaks size calculations |
entries:
|
isDocked()
|
Determine if the splitter is docked | - |
toggleDock()
|
Toggle docked or not |
dock: boolean
|
_handleDoubleClick()
|
Handle doubleclick (on splitter bar) to dock |
e:
|
_handleMouseDown()
|
Hide child iframes, they screw up sizing |
e:
|
_handleMouseUp()
|
Show any hidden children |
e:
|
_handleResize()
|
Handle a resize This includes notifying any manually resizing widgets, and updating preference if needed |
e: , timeout:
|
_handleTemplate()
|
HTML template for split handle | - |
Learn more about methods.
Inherited methods (21)
Et2Widget
| Name | Description |
|---|---|
checkCreateNamespace() |
Checks whether a namespace exists for this element in the content array. If yes, an own perspective of the content array is created. If not, the parent content manager is used. Constructor attributes are passed in case a child needs to make decisions |
clone() |
Creates a copy of this widget. |
createElementFromNode() |
Create a et2_widget from an XML node. First the type and attributes are read from the node. Then the readonly & modifications arrays are checked for changes specific to the loaded data. Then the appropriate constructor is called. After the constructor returns, the widget has a chance to further initialize itself from the XML node when the widget’s loadFromXML() method is called with the node. |
getArrayMgr() |
Returns the array manager object for the given part |
getArrayMgrs() |
Returns an associative array containing the top-most array managers. |
getChildren() |
Get child widgets Use |
getInstanceManager() |
Returns the instance manager |
getPath() |
Returns the path into the data array. By default, array manager takes care of this, but some extensions need to override this |
getRoot() |
Returns the base widget Usually this is the same as getInstanceManager().widgetContainer |
loadFromXML() |
Loads the widget tree from an XML node Overridden here to auto-assign slots if not set |
loadingFinished() |
Needed for legacy compatability. |
parseXMLAttrs() |
The parseXMLAttrs function takes an XML DOM attributes object and adds the given attributes to the _target associative array. This function also parses the legacyOptions. N.B. This is only used for legacy widgets. WebComponents use transformAttributes() and do their own handling of attributes. |
set_label() |
NOT the setter, since we cannot add to the DOM before connectedCallback() TODO: This is not best practice. Should just set property, DOM modification should be done in render https://lit-element.polymer-project.org/guide/templates#design-a-performant-template |
setArrayMgr() |
Sets the array manager for the given part |
setArrayMgrs() |
Sets all array manager objects - this function can be used to set the root array managers of the container object. |
setInstanceManager() |
Set the instance manager Normally this is not needed as it’s set on the top-level container, and we just return that reference |
_handleClick() |
Click handler calling custom handler set via onclick attribute to this.onclick |
destroy() |
et2_widget compatability |
set_class() |
Set the widget class |
set_disabled() |
Wrapper on this.disabled because legacy had it. |
set_statustext() |
supports legacy set_statustext |