The new HTML-5 DETAILS and DIALOG elements are supported now by most web-browsers. When you don't see a triangle-right below, your current browser doesn't support it.
DETAILS example.This is hidden content ...
<details>
<summary>Click to see a simple <code>DETAILS</code> example.</summary>
<p>This is hidden content ...</p>
</details>
An expand-control that works without scripting and arrow-resources!
<button onclick="toggleDialog('dialog');">Click to see a simple <code>DIALOG</code> example.</button>
<br>
<dialog id="dialog" onclick="toggleDialog('dialog');">
<p>You clicked me?!</p>
<p>What do you want?</p>
<p>I told you to not disturb me!</p>
<p>So now get out.</p>
</dialog>
<script>
var toggleDialog = function(elementId) {
var dialog = document.getElementById(elementId);
if (dialog.getAttribute("open") !== "")
dialog.setAttribute("open", "");
else
dialog.removeAttribute("open");
};
</script>
This needs some scripting to close the dialog upon various events, in this example by clicking onto it, or clicking onto its trigger button.
Both elements toggle their visibility when the attribute
openis set into them, or removed from them. In the DIALOG example you can see (in the script code) how this is done.
If you set the open attribute in HTML code, it would be initially open. The attribute doesn't need to have a value, it just needs to be present (unlike in XML).
Unfortunately the DETAILS element is not animated. Like the CSS display property, it does not support the CSS transition property.
Everything else is quite straight forward. You also can build trees with this.
1 | <style> |
The DIALOG element may require a little JS programming. Primarily you need to decide which user gestures should close the ....
1 | <dialog open id="dialog2" style="border: 3px solid gray; border-radius: 1em;"> |
The dialog's position is absolute, that means it doesn't take part in the layout flow. By default it will display vertically on the position where the layout contains it, and horizontally centered. Elements below the dialog will be covered by it. Therefore you always will need to program a way to close it.
By default the dialog has no title-bar, but you can style it fully, except the CSS position property. In the example shown here I added a traditional "Close" button.
Such a dialog could be used as rich-text custom tooltip, or context menu!
HTML-5 comes with a lot of new and nice features, and moves toward application programming. Web-applications don't need to import tons of JS and CSS user-interface resources any more. Nearly every desktop-application control is available also in browsers now. Unfortunately animations are still not supported out-of-the-box for open/close elements like DETAILS and DIALOG.
ɔ⃝ Fritz Ritzberger, 2017-10-27