UNPKG

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