On this page
Native Interactive Patterns
Prev: Media & Responsive Images | Up: tutorials | Next: css
Rel: Interactive & Scripting, Global Attributes, Vanilla Interactive Components
Ref: MDN Web Docs — Popover API
Tags: #public #web #html #tutorials #interactive
Contents
Zero-JS Popover Menu (popover)
The popover attribute promotes an element to the top layer with built-in Escape and click-outside ("light dismiss") behavior:
<button popovertarget="info-tip">Show info</button>
<div id="info-tip" popover>
<p>This popover closes automatically when you press Escape or click outside.</p>
</div>
Native Modal Dialog (<dialog>)
Pair <dialog> with <form method="dialog"> to close the modal natively and capture dialog.returnValue:
<dialog id="confirm-dialog">
<form method="dialog">
<p>Delete this item?</p>
<button value="cancel">Cancel</button>
<button value="confirm">Delete</button>
</form>
</dialog>
Open with document.getElementById("confirm-dialog").showModal() so the browser traps focus, renders ::backdrop, and restores focus to the trigger button on close.
Linked from
Related notes
- tuts/html/elements/interactive_and_scripting Linked here; links to this page; shared tags: #html, #interactive, #web
- tuts/html/tutorials Linked here; links to this page; shared tags: #html, #tutorials, #web
- tuts/html/tutorials/media_and_responsive_images Linked here; links to this page; shared tags: #html, #tutorials, #web
- tuts/web/tutorials/vanilla_interactive_components Linked here; links to this page; shared tags: #tutorials, #web
- tuts/html/attributes/global_attributes Linked here; shared tags: #html, #web
- tuts/css Linked here; shared tags: #web
- tuts/html/elements/interactive shared tags: #html, #interactive, #web
- tuts/html/elements/interactive/details shared tags: #html, #interactive, #web
- tuts/html/elements/interactive/dialog shared tags: #html, #interactive, #web
- tuts/html/elements/interactive/iframe shared tags: #html, #interactive, #web