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>radio</strong> component is an enhanced version of the standard HTML <code><input type="radio"></code>, or "radio button" element. A radio button consists of a small circle and, typically, text that clearly communicates a condition that will be set when the user clicks or touches it. Radio buttons always appear in groups of two or more and, while they can be individually selected, can only be deselected by selecting a different radio button in the same group (which deselects all other radio buttons in the group). The MDL radio component allows you to add display and click effects.</p> |
| 6 | <p>Radio buttons are a common feature of most user interfaces, regardless of a site's content or function. Their design and use is therefore an important factor in the overall user experience. See the radio component's <a href="https://www.google.com/design/spec/components/selection-controls.html#selection-controls-radio-button">Material Design specifications page</a> for details.</p> |
| 7 | <p>The enhanced radio component has a more vivid visual look than a standard radio button, and may be initially or programmatically <em>disabled</em>.</p> |
| 8 | <h3 id="to-include-an-mdl-radio-component-">To include an MDL <strong>radio</strong> component:</h3> |
| 9 | <p> 1. Code a <code><label></code> element and give it a <code>for</code> attribute whose value is the unique id of the radio button it will contain. The <code>for</code> attribute is optional when the <code><input></code> element is contained inside the <code><label></code> element, but is recommended for clarity.</p> |
| 10 | <pre><code class="lang-html"><label for="radio1"> |
| 11 | ... |
| 12 | </label> |
| 13 | </code></pre> |
| 14 | <p> 2. Inside the label, code an <code><input></code> element and give it a <code>type</code> attribute whose value is <code>"radio"</code>. Also give it an <code>id</code> attribute whose value matches the label's <code>for</code> attribute value, and a <code>name</code> attribute whose value identifies the radio button group. Optionally, give it a <code>value</code> attribute whose value provides some information about the radio button for scripting purposes.</p> |
| 15 | <pre><code class="lang-html"><label for="radio1"> |
| 16 | <input type="radio" id="radio1" name="flash" value="on"> |
| 17 | </label> |
| 18 | </code></pre> |
| 19 | <p> 3. Also inside the label, after the radio button, code a <code><span></code> element containing the radio button's text caption.</p> |
| 20 | <pre><code class="lang-html"><label for="radio1"> |
| 21 | <input type="radio" id="radio1" name="flash" value="on"> |
| 22 | <span>Always on</span> |
| 23 | </label> |
| 24 | </code></pre> |
| 25 | <p> 4. Add one or more MDL classes, separated by spaces, to the label, checkbox, and caption using the <code>class</code> attribute.</p> |
| 26 | <pre><code class="lang-html"><label for="radio1" class="mdl-radio mdl-js-radio"> |
| 27 | <input type="radio" id="radio1" name="flash" value="on" class="mdl-radio__button"> |
| 28 | <span class="mdl-radio__label">Always on</span> |
| 29 | </label> |
| 30 | </code></pre> |
| 31 | <p> 5. Repeat steps 1 through 4 for the other radio components in the group. For each one:</p> |
| 32 | <ul> |
| 33 | <li>on the <code>label</code> element, specify a unique <code>for</code> attribute value</li> |
| 34 | <li>on the <code>input</code> element, specify an <code>id</code> attribute value that matches its <code>label</code> element's <code>for</code> attribute value</li> |
| 35 | <li>on the <code>input</code> element, specify the same <code>name</code> attribute value for all radio components in the group</li> |
| 36 | <li>optionally, on the <code>input</code> element, specify a unique <code>value</code> attribute value</li> |
| 37 | </ul> |
| 38 | <p>The radio components are ready for use.</p> |
| 39 | <h4 id="example">Example</h4> |
| 40 | <p>A group of radio buttons to control a camera's flash setting.</p> |
| 41 | <pre><code class="lang-html"><label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="flash1"> |
| 42 | <input checked class="mdl-radio__button" id="flash1" name="flash" type="radio" |
| 43 | value="on"> |
| 44 | <span class="mdl-radio__label">Always on</span> |
| 45 | </label> |
| 46 | <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="flash2"> |
| 47 | <input class="mdl-radio__button" id="flash2" name="flash" type="radio" value="off"> |
| 48 | <span class="mdl-radio__label">Always off</span> |
| 49 | </label> |
| 50 | <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="flash3"> |
| 51 | <input class="mdl-radio__button" id="flash3" name="flash" type="radio" value="auto"> |
| 52 | <span class="mdl-radio__label">Automatic</span> |
| 53 | </label> |
| 54 | </code></pre> |
| 55 | <h2 id="configuration-options">Configuration options</h2> |
| 56 | <p>The MDL CSS classes apply various predefined visual and behavioral enhancements to the radio button. The table below lists the available classes and their effects.</p> |
| 57 | <table> |
| 58 | <thead> |
| 59 | <tr> |
| 60 | <th>MDL class</th> |
| 61 | <th>Effect</th> |
| 62 | <th>Remarks</th> |
| 63 | </tr> |
| 64 | </thead> |
| 65 | <tbody> |
| 66 | <tr> |
| 67 | <td><code>mdl-radio</code></td> |
| 68 | <td>Defines label as an MDL component</td> |
| 69 | <td>Required on label element</td> |
| 70 | </tr> |
| 71 | <tr> |
| 72 | <td><code>mdl-js-radio</code></td> |
| 73 | <td>Assigns basic MDL behavior to label</td> |
| 74 | <td>Required on label element</td> |
| 75 | </tr> |
| 76 | <tr> |
| 77 | <td><code>mdl-radio__button</code></td> |
| 78 | <td>Applies basic MDL behavior to radio</td> |
| 79 | <td>Required on input element (radio button)</td> |
| 80 | </tr> |
| 81 | <tr> |
| 82 | <td><code>mdl-radio__label</code></td> |
| 83 | <td>Applies basic MDL behavior to caption</td> |
| 84 | <td>Required on span element (caption)</td> |
| 85 | </tr> |
| 86 | <tr> |
| 87 | <td><code>mdl-js-ripple-effect</code></td> |
| 88 | <td>Applies <em>ripple</em> click effect</td> |
| 89 | <td>Optional; goes on label element, not input element (radio button)</td> |
| 90 | </tr> |
| 91 | </tbody> |
| 92 | </table> |
| 93 | <blockquote> |
| 94 | <p><strong>Note:</strong> Disabled versions of all the available radio button types are provided, and are invoked with the standard HTML boolean attribute <code>disabled</code>. <code><input type="radio" id="radio5" name="flash" class="mdl-radio__button" disabled></code> |
| 95 | This attribute may be added or removed programmatically via scripting.</p> |
| 96 | </blockquote> |
| 97 | |
| 98 | |