diff --git a/www/content/examples/_index.md b/www/content/examples/_index.md index bc98a29bd..97e57954d 100644 --- a/www/content/examples/_index.md +++ b/www/content/examples/_index.md @@ -34,6 +34,7 @@ You can copy and paste them and then adjust them for your needs. | [Dialogs - Browser](@/examples/dialogs.md) | Demonstrates the prompt and confirm dialogs | | [Dialogs - UIKit](@/examples/modal-uikit.md) | Demonstrates modal dialogs using UIKit | | [Dialogs - Bootstrap](@/examples/modal-bootstrap.md) | Demonstrates modal dialogs using Bootstrap | +| [Dialogs - Dialog Tag](@/examples/modal-dialog.md) | Demonstrates modal dialogs using html dialogs | | [Dialogs - Custom](@/examples/modal-custom.md) | Demonstrates modal dialogs from scratch | | [Tabs (Using HATEOAS)](@/examples/tabs-hateoas.md) | Demonstrates how to display and select tabs using HATEOAS principles | | [Tabs (Using JavaScript)](@/examples/tabs-javascript.md) | Demonstrates how to display and select tabs using JavaScript | diff --git a/www/content/examples/modal-dialog.md b/www/content/examples/modal-dialog.md new file mode 100644 index 000000000..367ddf743 --- /dev/null +++ b/www/content/examples/modal-dialog.md @@ -0,0 +1,91 @@ ++++ +title = "Modal Dialogs with HTML Dialogs" +template = "demo.html" ++++ + +Since 2022 the HTML spec has included a `` tag and it works well with +htmx. Consider the following html: + +```html + + + +``` + +This button sends a `GET` request to `/modal` when the button is clicked. The +server then responds with with a dialog that get swapped into an empty `
`. +The `` looks like this: + +```html + +

Modal Dialog

+ This is the modal content. You can put anything here, like text, + or a form, or an image. +
+
+ +
` +``` + +The close button fetches an empty `div` via the `/close` route to replace the dialog when it's closed: + +```html + +``` + +This essentially "resets" the page, and clicking the button again will open a new dialog. + +Note that in the dialog: +1. We use `hx-on::after-settle`. This is needed because in order for the dialog to actually be shown, +the `showModal` function must be called. +2. The `closedby` attribute is set to `none`. If we didn't have this, the user might close the dialog, +via some mechanism that doesn't trigger the fetch of the `/close` endpoint. + +{{ demoenv() }} + + + + + +