Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | |
| 2 | |
| 3 | |
| 4 | <h2 id="introduction">Introduction</h2> |
| 5 | <p>The Material Design Lite (MDL) <strong>dialog</strong> component allows for verification of |
| 6 | user actions, simple data input, and alerts to provide extra information to users.</p> |
| 7 | <h2 id="basic-usage">Basic Usage</h2> |
| 8 | <p>To use the dialog component, you must be using a browser that supports the <a href="http://www.w3.org/TR/2013/CR-html5-20130806/interactive-elements.html#the-dialog-element">dialog element</a>. |
| 9 | Only Chrome and Opera have native support at the time of writing. |
| 10 | For other browsers you will need to include the <a href="https://github.com/GoogleChrome/dialog-polyfill">dialog polyfill</a> or create your own.</p> |
| 11 | <p>Once you have dialog support create a dialog element. |
| 12 | The element when using the polyfill <strong>must</strong> be a child of the <code>body</code> element. |
| 13 | Within that container, add a content element with the class <code>mdl-dialog__content</code>. |
| 14 | Add you content, then create an action container with the class <code>mdl-dialog__actions</code>. |
| 15 | Finally for the markup, add your buttons within this container for triggering dialog functions.</p> |
| 16 | <p>Keep in mind, the order is automatically reversed for actions. |
| 17 | Material Design requires that the primary (confirmation) action be displayed last. |
| 18 | So, the first action you create will appear last on the action bar. |
| 19 | This allows for more natural coding and tab ordering while following the specification.</p> |
| 20 | <p>Remember to add the event handlers for your action items. |
| 21 | After your dialog markup is created, add the event listeners to the page to trigger the dialog to show.</p> |
| 22 | <p>For example:</p> |
| 23 | <pre><code class="lang-javascript"> var button = document.querySelector('button'); |
| 24 | var dialog = document.querySelector('dialog'); |
| 25 | button.addEventListener('click', function() { |
| 26 | dialog.showModal(); |
| 27 | /* Or dialog.show(); to show the dialog without a backdrop. */ |
| 28 | }); |
| 29 | </code></pre> |
| 30 | <h2 id="examples">Examples</h2> |
| 31 | <h3 id="simple-dialog">Simple Dialog</h3> |
| 32 | <p>See this example live in <a href="http://codepen.io/Garbee/full/EPoaMj/">codepen</a>.</p> |
| 33 | <pre><code class="lang-html"><body> |
| 34 | <button id="show-dialog" type="button" class="mdl-button">Show Dialog</button> |
| 35 | <dialog class="mdl-dialog"> |
| 36 | <h4 class="mdl-dialog__title">Allow data collection?</h4> |
| 37 | <div class="mdl-dialog__content"> |
| 38 | <p> |
| 39 | Allowing us to collect data will let us get you the information you want faster. |
| 40 | </p> |
| 41 | </div> |
| 42 | <div class="mdl-dialog__actions"> |
| 43 | <button type="button" class="mdl-button">Agree</button> |
| 44 | <button type="button" class="mdl-button close">Disagree</button> |
| 45 | </div> |
| 46 | </dialog> |
| 47 | <script> |
| 48 | var dialog = document.querySelector('dialog'); |
| 49 | var showDialogButton = document.querySelector('#show-dialog'); |
| 50 | if (! dialog.showModal) { |
| 51 | dialogPolyfill.registerDialog(dialog); |
| 52 | } |
| 53 | showDialogButton.addEventListener('click', function() { |
| 54 | dialog.showModal(); |
| 55 | }); |
| 56 | dialog.querySelector('.close').addEventListener('click', function() { |
| 57 | dialog.close(); |
| 58 | }); |
| 59 | </script> |
| 60 | </body> |
| 61 | </code></pre> |
| 62 | <h3 id="dialog-with-full-width-actions">Dialog with full width actions</h3> |
| 63 | <p>See this example live in <a href="http://codepen.io/Garbee/full/JGMowG/">codepen</a>.</p> |
| 64 | <pre><code class="lang-html"><body> |
| 65 | <button type="button" class="mdl-button show-modal">Show Modal</button> |
| 66 | <dialog class="mdl-dialog"> |
| 67 | <div class="mdl-dialog__content"> |
| 68 | <p> |
| 69 | Allow this site to collect usage data to improve your experience? |
| 70 | </p> |
| 71 | </div> |
| 72 | <div class="mdl-dialog__actions mdl-dialog__actions--full-width"> |
| 73 | <button type="button" class="mdl-button">Agree</button> |
| 74 | <button type="button" class="mdl-button close">Disagree</button> |
| 75 | </div> |
| 76 | </dialog> |
| 77 | <script> |
| 78 | var dialog = document.querySelector('dialog'); |
| 79 | var showModalButton = document.querySelector('.show-modal'); |
| 80 | if (! dialog.showModal) { |
| 81 | dialogPolyfill.registerDialog(dialog); |
| 82 | } |
| 83 | showModalButton.addEventListener('click', function() { |
| 84 | dialog.showModal(); |
| 85 | }); |
| 86 | dialog.querySelector('.close').addEventListener('click', function() { |
| 87 | dialog.close(); |
| 88 | }); |
| 89 | </script> |
| 90 | </body> |
| 91 | </code></pre> |
| 92 | <h2 id="css-classes">CSS Classes</h2> |
| 93 | <h3 id="blocks">Blocks</h3> |
| 94 | <table> |
| 95 | <thead> |
| 96 | <tr> |
| 97 | <th>MDL Class</th> |
| 98 | <th>Effect</th> |
| 99 | <th>Remarks</th> |
| 100 | </tr> |
| 101 | </thead> |
| 102 | <tbody> |
| 103 | <tr> |
| 104 | <td><code>mdl-dialog</code></td> |
| 105 | <td>Defines the container of the dialog component.</td> |
| 106 | <td>Required on dialog container.</td> |
| 107 | </tr> |
| 108 | </tbody> |
| 109 | </table> |
| 110 | <h3 id="elements">Elements</h3> |
| 111 | <table> |
| 112 | <thead> |
| 113 | <tr> |
| 114 | <th>MDL Class</th> |
| 115 | <th>Effect</th> |
| 116 | <th>Remarks</th> |
| 117 | </tr> |
| 118 | </thead> |
| 119 | <tbody> |
| 120 | <tr> |
| 121 | <td><code>mdl-dialog__title</code></td> |
| 122 | <td>Defines the title container in the dialog.</td> |
| 123 | <td>Optional on title container.</td> |
| 124 | </tr> |
| 125 | <tr> |
| 126 | <td><code>mdl-dialog__content</code></td> |
| 127 | <td>Defines the content container of the dialog.</td> |
| 128 | <td>Required on content container.</td> |
| 129 | </tr> |
| 130 | <tr> |
| 131 | <td><code>mdl-dialog__actions</code></td> |
| 132 | <td>Defines the actions container in the dialog.</td> |
| 133 | <td>Required on action container.</td> |
| 134 | </tr> |
| 135 | </tbody> |
| 136 | </table> |
| 137 | <h3 id="modifiers">Modifiers</h3> |
| 138 | <table> |
| 139 | <thead> |
| 140 | <tr> |
| 141 | <th>MDL Class</th> |
| 142 | <th>Effect</th> |
| 143 | <th>Remarks</th> |
| 144 | </tr> |
| 145 | </thead> |
| 146 | <tbody> |
| 147 | <tr> |
| 148 | <td><code>mdl-dialog__actions--full-width</code></td> |
| 149 | <td>Modifies the actions to each take the full width of the container. This makes each take their own line.</td> |
| 150 | <td>Optional on action container.</td> |
| 151 | </tr> |
| 152 | </tbody> |
| 153 | </table> |
| 154 | |
| 155 | |