44[ ![ License] ( https://img.shields.io/github/license/fylgja/alpinejs-dialog?color=%23234 )] ( /LICENSE )
55[ ![ Netlify Status] ( https://api.netlify.com/api/v1/badges/f6d1c1a3-2365-4d56-aeb4-ec52bcc7c1b6/deploy-status )] ( https://alpinejs-dialog.netlify.app/ )
66
7- Bring the power of AlpineJs to the HTML dialog.
7+ Bring the power and simplicity of Alpine.js to the native HTML ` < dialog> ` element .
88
9- See it in action here https://alpinejs-dialog.netlify.app/
9+ ** Live Demo: ** https://alpinejs-dialog.netlify.app/
1010
1111## Installation
1212
@@ -40,9 +40,9 @@ just make sure to include it before AlpineJs.
4040<
script defer src =
" https://unpkg.com/[email protected] /dist/cdn.min.js" ></
script >
4141```
4242
43- ## How to use
43+ ## Usage
4444
45- To use this, create an Alpine component for example, like;
45+ To utilize the ` x-htmldialog ` plugin, add the directive to an HTML ` <dialog> ` element that is also controlled by ` x-show ` .
4646
4747``` html
4848<div x-data =" { open: false }" >
@@ -51,18 +51,20 @@ To use this, create an Alpine component for example, like;
5151</div >
5252```
5353
54- When adding the ` x-htmldialog ` to an ` x-show ` element,
55- it will not toggle the display,
56- but instead use the native ` el.showModal() ` function.
54+ When the ` x-htmldialog ` directive is present on an ` x-show ` element:
5755
58- The value inside the ` x-htmldialog ` is not required,
59- but is recommended to close the dialog using the escape key or clicking the backdrop.
56+ - It prevents ` x-show ` from directly toggling the display style.
57+ - Instead, it uses the native ` el.showModal() ` function to display the dialog.
58+ - The optional value provided to ` x-htmldialog ` (e.g., ` "open = false" ` ) is executed
59+ when the dialog is closed by pressing the Escape key or clicking outside the dialog (the backdrop).
6060
6161### Modifiers
6262
63- #### Scroll-lock
63+ The ` x-htmldialog ` directive supports modifiers to further customize its behavior.
6464
65- To lock the page scroll add the modifier ` noscroll ` ;
65+ #### ` noscroll `
66+
67+ The ` noscroll ` modifier prevents scrolling on the background page while the dialog is open.
6668
6769``` html
6870<div x-data =" { open: false }" >
@@ -71,4 +73,25 @@ To lock the page scroll add the modifier `noscroll`;
7173</div >
7274```
7375
74- This will now prevent any scrolling on the page.
76+ #### ` closeby `
77+
78+ The ` closeby ` modifier allows you to control which events trigger the close action
79+ defined in the ` x-htmldialog ` value (backdrop click and/or Escape key press).
80+
81+ This mimics the upcoming native ` closeby ` behavior of the ` <dialog> ` element.
82+
83+ Available options for the ` closeby ` modifier:
84+
85+ - ` .auto ` (Same as ` .closerequest ` ). Only triggers the close action on the Escape key press.
86+ - ` .none ` Disables all automatic close triggers (backdrop click and Escape key).
87+ - ` .closerequest ` Only triggers the close action on the Escape key press.
88+ - ` .any ` (Default behavior if no ` closeby ` modifier is present).
89+ Triggers the close action on both backdrop clicks and Escape key presses.
90+
91+ Example, for disable all automatic closing:
92+
93+ ``` html
94+ <dialog x-show =" open" x-htmldialog.closeby.none =" open = false" >...</dialog >
95+ ```
96+
97+ This way you can keep the close trigger for form submissions and prevent any other close triggers.
0 commit comments