Skip to main content
Light Dark System

Details

<et2-details> | Et2Details

Overview

Details show a brief summary and expand to show additional content

et2-details shows a summary line and expands to reveal the rest. Use it for the parts of a form that most users do not need - advanced options, rarely used address fields, a long description.

It is a thin wrapper around Shoelace’s <sl-details>, so summary, open, disabled, the show() / hide() methods and the sl-show / sl-hide events all behave as documented there. The attributes below are the eTemplate additions.

Content inside a closed details is still in the DOM, still submitted, and still found by getWidgetById(). If you need it gone rather than collapsed, use disabled on the widgets themselves.

Examples

Summary and content

summary is the always-visible line. Anything else you put inside is the content that appears when it is opened.

Keep a copy in Sent Request a read receipt
<et2-details summary="Advanced options">
    <et2-vbox>
        <et2-checkbox>Keep a copy in Sent</et2-checkbox>
        <et2-checkbox>Request a read receipt</et2-checkbox>
    </et2-vbox>
</et2-details>

Open by default

<et2-details summary="Already open" open>
    <et2-description value="Visible without a click."></et2-description>
</et2-details>

Toggle on the left

The expand arrow sits at the right end of the summary. toggleAlign="left" puts it in front of the summary text instead, which reads better for a short label in a narrow column.

<et2-details summary="Arrow on the right">
    <et2-description value="Default"></et2-description>
</et2-details>
<et2-details summary="Arrow on the left" toggleAlign="left">
    <et2-description value="toggleAlign=left"></et2-description>
</et2-details>

Opening on hover

toggleOnHover opens the details when the pointer enters it and closes it again when the pointer leaves. Handy for a preview or a toolbar overflow; avoid it for anything the user has to interact with, since moving the mouse to a field inside can close it on the way.

<et2-details summary="Hover over me" toggleOnHover>
    <et2-description value="Opened without a click."></et2-description>
</et2-details>

Accordion

Give several details the same accordionGroup and opening one closes the others. The group is matched by name across the whole document, so pick something specific to the template.

<et2-details summary="Contact" accordionGroup="details-accordion-example">
    <et2-description value="One at a time."></et2-description>
</et2-details>
<et2-details summary="Delivery" accordionGroup="details-accordion-example">
    <et2-description value="Opening this closes the others."></et2-description>
</et2-details>
<et2-details summary="Payment" accordionGroup="details-accordion-example">
    <et2-description value="And this one closes that."></et2-description>
</et2-details>

Breaking out of the container

By default the content pushes everything below it down. hoist positions the content fixed instead, so it floats over the following content and the surrounding layout does not move. Use it when the details lives in a toolbar or a table cell that must not change height.

<div style="border: 1px solid var(--sl-color-neutral-300); padding: var(--sl-spacing-small)">
    <et2-details summary="Hoisted" hoist>
        <et2-description value="Floats over the text below."></et2-description>
    </et2-details>
    <et2-description value="This line does not move when the details opens."></et2-description>
</div>

Overlaying the summary

overlaySummaryOnOpen lets the open content cover the summary line, so the widget takes no more room open than closed apart from the content itself. Combine it with toggleAlign to choose which side the toggle stays on.

<et2-details summary="Search" overlaySummaryOnOpen>
    <et2-textbox placeholder="Covers the summary"></et2-textbox>
</et2-details>

Reacting to open and close

The Shoelace sl-show and sl-hide events fire on open and close. sl-show is also what accordionGroup listens to.

Last event: none

<et2-details id="details-event-example" summary="Watch the log">
    <et2-description value="Open and close me."></et2-description>
</et2-details>
<p>Last event: <span id="details-event-output">none</span></p>
<script>
    const details = document.getElementById("details-event-example");
    const out = document.getElementById("details-event-output");
    details.addEventListener("sl-show", () => {out.textContent = "sl-show";});
    details.addEventListener("sl-hide", () => {out.textContent = "sl-hide";});
</script>

Disabled hides it

Shoelace’s <sl-details> greys itself out when disabled, but the eTemplate base widget applies display: none to any disabled widget that is not an input, and a details is not an input. So disabled here removes the whole thing - summary and all - exactly like hidden.

The two details below are in the preview; only the first one is on the page.

<et2-details summary="Enabled">
    <et2-description value="Visible"></et2-description>
</et2-details>
<et2-details summary="Disabled - you cannot see this" disabled>
    <et2-description value="Unreachable"></et2-description>
</et2-details>

If you want the summary to stay on screen but not open, disabled is not it - leave the details enabled and disable the widgets inside.

Slots

Name Description
(default) The details’ main content.
summary The details’ summary. Alternatively, you can use the summary attribute.
expand-icon Optional expand icon to use instead of the default. Works best with .
collapse-icon Optional collapse icon to use instead of the default. Works best with .

Learn more about using slots.

Properties

Name Description Reflects Type Default
accordionGroup Group multiple details together so only one can be open at once string -
hoist Makes details content fixed position to break out of the container boolean false
overlaySummaryOnOpen Overlay summary container with the details container when in open state boolean false
toggleAlign set toggle alignment either to left or right. Default is right alignment. "right" | "left" "right"
toggleOnHover Toggle when hover over boolean false
translate
List of properties that get translated Done separately to not interfere with properties - if we re-define label property, labels go missing. - -

Learn more about attributes and properties.

Inherited properties (20)

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

SlDetails⁠ (Shoelace)

Name Description
open Indicates whether or not the details is open. You can toggle this attribute to show and hide the details, or you can use the show() and hide() methods and this attribute will reflect the details’ open state.
summary The summary to show in the header. If you need to display HTML, use the summary slot instead.

LitElement

Name Description
updateComplete A read-only promise that resolves when the component has finished updating.

Methods

Name Description Arguments
_mouseOutEvent() Handle mouse out event for hiding out details event:

Learn more about methods.

Inherited methods (23)

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 .children to get web component children
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
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

SlDetails⁠ (Shoelace)

Name Description
hide() Hides the details
show() Shows the details.

Parts

Name Description
base Component wrapper
header Header content
summary-icon expand / collapse icon wrapper
content The details’ main content

Learn more about customizing CSS parts.