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>slider</strong> component is an enhanced version of the new HTML5 <code><input type="range"></code> element. A slider consists of a horizontal line upon which sits a small, movable disc (the <em>thumb</em>) and, typically, text that clearly communicates a value that will be set when the user moves it.</p> |
| 6 | <p>Sliders are a fairly new feature in user interfaces, and allow users to choose a value from a predetermined range by moving the thumb through the range (lower values to the left, higher values to the right). Their design and use is an important factor in the overall user experience. See the slider component's <a href="http://www.google.com/design/spec/components/sliders.html">Material Design specifications page</a> for details.</p> |
| 7 | <p>The enhanced slider component may be initially or programmatically <em>disabled</em>.</p> |
| 8 | <h3 id="to-include-an-mdl-slider-component-">To include an MDL <strong>slider</strong> component:</h3> |
| 9 | <p> 1. Code a <code><p></code> paragraph element and style it as desired. Include a CSS <code>width</code> property (directly or via a CSS class), which determines the slider's size.</p> |
| 10 | <pre><code class="lang-html"><p style="width:300px"> |
| 11 | ... |
| 12 | </p> |
| 13 | </code></pre> |
| 14 | <p> 2. Inside the paragraph container, code an <code><input></code> element and give it a <code>type</code> attribute whose value is <code>"range"</code>. Also give it an <code>id</code> attribute to make it available for scripting, and <code>min</code> and <code>max</code> attributes whose values specify the slider's range. Give it a <code>value</code> attribute whose value sets the initial thumb position (optional; if omitted, defaults to 50% of the maximum), and a <code>step</code> attribute whose value specifies the increment by which the thumb moves (also optional; if omitted, defaults to 1). Finally, give it an event handler to be executed when the user changes the slider's value.</p> |
| 15 | <pre><code class="lang-html"><p style="width:300px"> |
| 16 | <input type="range" id="s1" min="0" max="10" value="4" step="2"> |
| 17 | </p> |
| 18 | </code></pre> |
| 19 | <p> 3. Add one or more MDL classes, separated by spaces, to the slider using the <code>class</code> attribute.</p> |
| 20 | <pre><code class="lang-html"><p style="width:300px"> |
| 21 | <input class="mdl-slider mdl-js-slider" type="range" id="s1" min="0" max="10" value="4" step="2"> |
| 22 | </p> |
| 23 | </code></pre> |
| 24 | <p>The slider component is ready for use.</p> |
| 25 | <h4 id="example">Example</h4> |
| 26 | <p>A slider that controls volume.</p> |
| 27 | <pre><code class="lang-html"><p style="width:300px"> |
| 28 | <input class="mdl-slider mdl-js-slider" type="range" id="s1" min="0" max="10" value="4" step="2"> |
| 29 | </p> |
| 30 | </code></pre> |
| 31 | <h2 id="configuration-options">Configuration options</h2> |
| 32 | <p>The MDL CSS classes apply various predefined visual and behavioral enhancements to the slider. The table below lists the available classes and their effects.</p> |
| 33 | <table> |
| 34 | <thead> |
| 35 | <tr> |
| 36 | <th>MDL class</th> |
| 37 | <th>Effect</th> |
| 38 | <th>Remarks</th> |
| 39 | </tr> |
| 40 | </thead> |
| 41 | <tbody> |
| 42 | <tr> |
| 43 | <td><code>mdl-slider</code></td> |
| 44 | <td>Defines input element as an MDL component</td> |
| 45 | <td>Required</td> |
| 46 | </tr> |
| 47 | <tr> |
| 48 | <td><code>mdl-js-slider</code></td> |
| 49 | <td>Assigns basic MDL behavior to input element</td> |
| 50 | <td>Required</td> |
| 51 | </tr> |
| 52 | </tbody> |
| 53 | </table> |
| 54 | <blockquote> |
| 55 | <p><strong>Note:</strong> A disabled version of the slider is provided, and is invoked with the standard HTML boolean attribute <code>disabled</code>. <code><input class="mdl-slider mdl-js-slider" type="range" id="s1" min="0" max="10" value="4" step="2" disabled></code> |
| 56 | This attribute may be added or removed programmatically via scripting.</p> |
| 57 | <p><strong>Note:</strong> Although the <em>value</em> attribute is used to set a slider's initial value, it should not be used |
| 58 | to modify the value programmatically; instead, use the MDL <code>change()</code> method. For example, assuming |
| 59 | that <em>slider1</em> is a slider object and <em>newvalue</em> is a variable containing the desired value, do not |
| 60 | use <code>slider1.value = newvalue</code>; instead, use <code>slider1.MaterialSlider.change(newvalue)</code>.</p> |
| 61 | </blockquote> |
| 62 | <h2 id="license">License</h2> |
| 63 | <p>Copyright Google, 2015. Licensed under an Apache-2 license.</p> |
| 64 | |
| 65 | |