{modal}
A dialog over the page with the button that opens it - works with and without JavaScript.
Syntax
{modal 'name'} ... {/modal}
{modal 'name', title='Heading', button='Button text'} ... {/modal}
Parameters
-
name -
Letters, digits,
_and-, at most 64. The dialog's id ispad-modal-<name>.
Options
-
title - The heading of the dialog, which also names it for a screen reader. The button's text when not given.
-
button -
The text of the button that opens the dialog,
Openwhen not given.
Description
{modal} writes an HTML <dialog> holding its content, with the heading from title=, and a button that opens it. The content renders first; on the end walk the tag puts it in the dialog. The name is required and becomes the id pad-modal-<name>, so an address ending in #pad-modal-terms opens that dialog on arrival.
The button opens the dialog as a modal in the first way the browser can: the HTML invoker commands (commandfor, command="show-modal") where it has them; otherwise a small script, written once per page (with the CSP nonce when $padCsp asks for one), that calls showModal() and close(); and with scripting off a link to the dialog's id, shown by the CSS as an overlay with a close link back to the opener. Opened, the page behind is inert, the focus moves into the dialog and back to the button afterwards, and Escape, the close button or a click on the backdrop closes it.
title= heads and names the dialog; button= is the button text, Open by default; a dialog without a title takes the button text as its heading. A name that is not letters, digits, _ and - is an error under the strict check, as is a {modal} that never closes. The colours are --pad-modal-accent, -on, -text, -muted, -line, -surface and -backdrop on .pad-modal.
Examples
Terms in a dialog
A button that opens the terms of sale over the page.
<p>Your order: 1 × Aurora electric kettle, <strong>€ 79.00</strong></p>
{modal 'terms', title='Terms of sale', button='Read the terms'}
<ol>
<li>Prices include VAT; shipping is free above € 50.</li>
<li>You may return an unused product within 30 days.</li>
</ol>
{/modal}
Your order: 1 × Aurora electric kettle, € 79.00
Read the termsRendered content
The content is template - here a loop over the page's data - rendered before it goes into the dialog.
{modal 'opening-hours', button='Opening hours'}
<table>
{hours}<tr><th>{$day}</th><td>{$open}</td></tr>{/hours}
</table>
{/modal}
<?php
$hours = [
[ 'day' => 'Monday to Friday', 'open' => '09:00 - 18:00' ],
[ 'day' => 'Saturday', 'open' => '10:00 - 16:00' ],
[ 'day' => 'Sunday', 'open' => 'closed' ] ];
?>
See also
- {tabs} Panels behind a row of tabs, switched by radio buttons and CSS - no JavaScript.
- {accordion} Items that open and close on a click, each a details element - no JavaScript.
- {carousel} Slides in a row that scrolls and snaps sideways, with arrow links and dots - no JavaScript needed.
- {copy} A text in a code block with a button that copies it to the clipboard.