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>menu</strong> component is a user interface element that allows users to select one of a number of options. The selection typically results in an action initiation, a setting change, or other observable effect. Menu options are always presented in sets of two or more, and options may be programmatically enabled or disabled as required. The menu appears when the user is asked to choose among a series of options, and is usually dismissed after the choice is made.</p> |
| 6 | <p>Menus are an established but non-standardized feature in user interfaces, and allow users to make choices that direct the activity, progress, or characteristics of software. Their design and use is an important factor in the overall user experience. See the menu component's <a href="http://www.google.com/design/spec/components/menus.html">Material Design specifications page</a> for details.</p> |
| 7 | <h3 id="to-include-an-mdl-menu-component-">To include an MDL <strong>menu</strong> component:</h3> |
| 8 | <blockquote> |
| 9 | <p><strong>Note:</strong> The menu requires a non-static positioned parent element. Positioning options may not work properly if the menu is inside of a statically positioned node.</p> |
| 10 | </blockquote> |
| 11 | <p> 1. Code a <code><button></code> element; this is the clickable toggle that will show and hide the menu options. Include an <code>id</code> attribute whose value will match the <code>for</code> (or <code>data-mdl-for</code>) attribute of the unordered list coded in the next step. Inside the button, code a <code><i></code> or <code><span></code> element to contain an icon of your choice.</p> |
| 12 | <pre><code class="lang-html"><button id="menu1"> |
| 13 | <i></i> |
| 14 | </button> |
| 15 | </code></pre> |
| 16 | <p> 2. Code a <code><ul></code> unordered list element; this is the container that holds the options. Include a <code>for</code> attribute whose value matches the <code>id</code> attribute of the button element.</p> |
| 17 | <pre><code class="lang-html"><ul for="menu1"> |
| 18 | </ul> |
| 19 | </code></pre> |
| 20 | <p> 3. Inside the unordered list, code one <code><li></code> element for each option. Include any desired attributes and values, such as an id or event handler, and add a text caption as appropriate.</p> |
| 21 | <pre><code class="lang-html"><ul for="menu1"> |
| 22 | <li>Continue</li> |
| 23 | <li>Stop</li> |
| 24 | <li>Pause</li> |
| 25 | </ul> |
| 26 | </code></pre> |
| 27 | <p> 4. Add one or more MDL classes, separated by spaces, to the button and span elements using the <code>class</code> attribute.</p> |
| 28 | <pre><code class="lang-html"><button id="menu1" class="mdl-button mdl-js-button mdl-button--icon"> |
| 29 | <i class="material-icons">more_vert</i> |
| 30 | </button> |
| 31 | </code></pre> |
| 32 | <p> 5. Add one or more MDL classes, separated by spaces, to the unordered list and the list items using the <code>class</code> attribute.</p> |
| 33 | <pre><code class="lang-html"><ul class="mdl-menu mdl-js-menu" for="menu1"> |
| 34 | <li class="mdl-menu__item">Continue</li> |
| 35 | <li class="mdl-menu__item">Stop</li> |
| 36 | <li class="mdl-menu__item">Pause</li> |
| 37 | </ul> |
| 38 | </code></pre> |
| 39 | <p>The menu component is ready for use.</p> |
| 40 | <h4 id="examples">Examples</h4> |
| 41 | <p>A menu with three options.</p> |
| 42 | <pre><code class="lang-html"><button id="menu-speed" class="mdl-button mdl-js-button mdl-button--icon"> |
| 43 | <i class="material-icons">more_vert</i> |
| 44 | </button> |
| 45 | <ul class="mdl-menu mdl-js-menu" for="menu-speed"> |
| 46 | <li class="mdl-menu__item">Fast</li> |
| 47 | <li class="mdl-menu__item">Medium</li> |
| 48 | <li class="mdl-menu__item">Slow</li> |
| 49 | </ul> |
| 50 | </code></pre> |
| 51 | <p>A menu with three options, with ripple effect on button and option links.</p> |
| 52 | <pre><code class="lang-html"><button id="menu-speed" class="mdl-button mdl-js-button mdl-button--icon"> |
| 53 | <i class="material-icons">more_vert</i> |
| 54 | </button> |
| 55 | <ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect" for="menu-speed"> |
| 56 | <li class="mdl-menu__item">Fast</li> |
| 57 | <li class="mdl-menu__item">Medium</li> |
| 58 | <li class="mdl-menu__item">Slow</li> |
| 59 | </ul> |
| 60 | </code></pre> |
| 61 | <p>A menu with three options, the second of which is disabled by default.</p> |
| 62 | <pre><code class="lang-html"><button id="menu-speed" class="mdl-button mdl-js-button mdl-button--icon"> |
| 63 | <i class="material-icons">more_vert</i> |
| 64 | </button> |
| 65 | <ul class="mdl-menu mdl-js-menu" for="menu-speed"> |
| 66 | <li class="mdl-menu__item">Fast</li> |
| 67 | <li class="mdl-menu__item" disabled>Medium</li> |
| 68 | <li class="mdl-menu__item">Slow</li> |
| 69 | </ul> |
| 70 | </code></pre> |
| 71 | <h2 id="configuration-options">Configuration options</h2> |
| 72 | <p>The MDL CSS classes apply various predefined visual and behavioral enhancements to the menu. The table below lists the available classes and their effects.</p> |
| 73 | <table> |
| 74 | <thead> |
| 75 | <tr> |
| 76 | <th>MDL class</th> |
| 77 | <th>Effect</th> |
| 78 | <th>Remarks</th> |
| 79 | </tr> |
| 80 | </thead> |
| 81 | <tbody> |
| 82 | <tr> |
| 83 | <td><code>mdl-button</code></td> |
| 84 | <td>Defines button as an MDL component</td> |
| 85 | <td>Required on button element</td> |
| 86 | </tr> |
| 87 | <tr> |
| 88 | <td><code>mdl-js-button</code></td> |
| 89 | <td>Assigns basic MDL behavior to button</td> |
| 90 | <td>Required on button element</td> |
| 91 | </tr> |
| 92 | <tr> |
| 93 | <td><code>mdl-button--icon</code></td> |
| 94 | <td>Applies <em>icon</em> (small plain circular) display effect to button</td> |
| 95 | <td>Required on button element</td> |
| 96 | </tr> |
| 97 | <tr> |
| 98 | <td><code>material-icons</code></td> |
| 99 | <td>Defines span as a material icon</td> |
| 100 | <td>Required on an inline element</td> |
| 101 | </tr> |
| 102 | <tr> |
| 103 | <td><code>mdl-menu</code></td> |
| 104 | <td>Defines an unordered list container as an MDL component</td> |
| 105 | <td>Required on ul element</td> |
| 106 | </tr> |
| 107 | <tr> |
| 108 | <td><code>mdl-js-menu</code></td> |
| 109 | <td>Assigns basic MDL behavior to menu</td> |
| 110 | <td>Required on ul element</td> |
| 111 | </tr> |
| 112 | <tr> |
| 113 | <td><code>mdl-menu__item</code></td> |
| 114 | <td>Defines buttons as MDL menu options and assigns basic MDL behavior</td> |
| 115 | <td>Required on list item elements</td> |
| 116 | </tr> |
| 117 | <tr> |
| 118 | <td><code>mdl-menu__item--full-bleed-divider</code></td> |
| 119 | <td>Modifies an item to have a full bleed divider between it and the next list item.</td> |
| 120 | <td>Optional on list item elements</td> |
| 121 | </tr> |
| 122 | <tr> |
| 123 | <td><code>mdl-js-ripple-effect</code></td> |
| 124 | <td>Applies <em>ripple</em> click effect to option links</td> |
| 125 | <td>Optional; goes on unordered list element</td> |
| 126 | </tr> |
| 127 | <tr> |
| 128 | <td><code>mdl-menu--top-left</code></td> |
| 129 | <td>Positions menu above button, aligns left edge of menu with button</td> |
| 130 | <td>Optional; goes on unordered list element</td> |
| 131 | </tr> |
| 132 | <tr> |
| 133 | <td>(none)</td> |
| 134 | <td>Positions menu below button, aligns left edge of menu with button</td> |
| 135 | <td>Default</td> |
| 136 | </tr> |
| 137 | <tr> |
| 138 | <td><code>mdl-menu--top-right</code></td> |
| 139 | <td>Positions menu above button, aligns right edge of menu with button</td> |
| 140 | <td>Optional; goes on unordered list element</td> |
| 141 | </tr> |
| 142 | <tr> |
| 143 | <td><code>mdl-menu--bottom-right</code></td> |
| 144 | <td>Positions menu below button, aligns right edge of menu with button</td> |
| 145 | <td>Optional; goes on unordered list element</td> |
| 146 | </tr> |
| 147 | </tbody> |
| 148 | </table> |
| 149 | <p>(1) The "more-vert" icon class is used here as an example. Other icons can be used by modifying the class name. For a list of available icons, see <a href="http://google.github.io/web-starter-kit/latest/styleguide/icons/demo.html">this page</a>; hover over an icon to see its class name.</p> |
| 150 | <p>(2) The <code>i</code> or <code>span</code> element in "button"" element can be used interchangeably.</p> |
| 151 | <blockquote> |
| 152 | <p><strong>Note:</strong> Disabled versions of the menu options are provided, and are invoked with the standard HTML boolean attribute <code>disabled</code> or <code>data-mdl-disabled</code>. <code><li class="mdl-menu__item" disabled>Medium</li></code> |
| 153 | This attribute may be added or removed programmatically via scripting.</p> |
| 154 | </blockquote> |
| 155 | |
| 156 | |