OLD | NEW |
1 <!-- | 1 <!-- |
2 @license | 2 @license |
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
7 Code distributed by Google as part of the polymer project is also | 7 Code distributed by Google as part of the polymer project is also |
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
9 --> | 9 --> |
10 | 10 |
11 <link rel="import" href="../polymer/polymer.html"> | 11 <link rel="import" href="../polymer/polymer.html"> |
12 <link rel="import" href="../paper-styles/paper-styles.html"> | 12 <link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> |
| 13 <link rel="import" href="../paper-styles/color.html"> |
13 <link rel="import" href="../paper-progress/paper-progress.html"> | 14 <link rel="import" href="../paper-progress/paper-progress.html"> |
14 <link rel="import" href="../paper-input/paper-input.html"> | 15 <link rel="import" href="../paper-input/paper-input.html"> |
15 <link rel="import" href="../paper-behaviors/paper-inky-focus-behavior.html"> | 16 <link rel="import" href="../paper-behaviors/paper-inky-focus-behavior.html"> |
16 <link rel="import" href="../paper-ripple/paper-ripple.html"> | 17 <link rel="import" href="../paper-ripple/paper-ripple.html"> |
17 <link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html
"> | 18 <link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html
"> |
18 <link rel="import" href="../iron-range-behavior/iron-range-behavior.html"> | 19 <link rel="import" href="../iron-range-behavior/iron-range-behavior.html"> |
19 <link rel="import" href="../iron-form-element-behavior/iron-form-element-behavio
r.html"> | 20 <link rel="import" href="../iron-form-element-behavior/iron-form-element-behavio
r.html"> |
20 | 21 |
21 <!-- | 22 <!-- |
| 23 Material design: [Sliders](https://www.google.com/design/spec/components/sliders
.html) |
| 24 |
22 `paper-slider` allows user to select a value from a range of values by | 25 `paper-slider` allows user to select a value from a range of values by |
23 moving the slider thumb. The interactive nature of the slider makes it a | 26 moving the slider thumb. The interactive nature of the slider makes it a |
24 great choice for settings that reflect intensity levels, such as volume, | 27 great choice for settings that reflect intensity levels, such as volume, |
25 brightness, or color saturation. | 28 brightness, or color saturation. |
26 | 29 |
27 Example: | 30 Example: |
28 | 31 |
29 <paper-slider></paper-slider> | 32 <paper-slider></paper-slider> |
30 | 33 |
31 Use `min` and `max` to specify the slider range. Default is 0 to 100. | 34 Use `min` and `max` to specify the slider range. Default is 0 to 100. |
(...skipping 22 matching lines...) Expand all Loading... |
54 `--paper-slider-pin-start-color` | The color of the pin at the far left | `#c8c8
c8` | 57 `--paper-slider-pin-start-color` | The color of the pin at the far left | `#c8c8
c8` |
55 `--paper-slider-height` | Height of the progress bar | `2px` | 58 `--paper-slider-height` | Height of the progress bar | `2px` |
56 | 59 |
57 @group Paper Elements | 60 @group Paper Elements |
58 @element paper-slider | 61 @element paper-slider |
59 @demo demo/index.html | 62 @demo demo/index.html |
60 @hero hero.svg | 63 @hero hero.svg |
61 --> | 64 --> |
62 | 65 |
63 <dom-module id="paper-slider"> | 66 <dom-module id="paper-slider"> |
64 | 67 <template strip-whitespace> |
65 <link rel="import" type="css" href="paper-slider.css"> | 68 <style> |
66 | 69 :host { |
67 <template> | 70 display: inline-block; |
| 71 width: 200px; |
| 72 cursor: default; |
| 73 -webkit-user-select: none; |
| 74 -moz-user-select: none; |
| 75 -ms-user-select: none; |
| 76 user-select: none; |
| 77 -webkit-tap-highlight-color: rgba(0, 0, 0, 0); |
| 78 --paper-progress-active-color: var(--paper-slider-active-color, --google
-blue-700); |
| 79 --paper-progress-secondary-color: var(--paper-slider-secondary-color, --
google-blue-300); |
| 80 --paper-progress-disabled-active-color: var(--paper-slider-disabled-acti
ve-color, --google-grey-500); |
| 81 --paper-progress-disabled-secondary-color: var(--paper-slider-disabled-s
econdary-color, --google-grey-300); |
| 82 } |
| 83 |
| 84 /* focus shows the ripple */ |
| 85 :host(:focus) { |
| 86 outline: none; |
| 87 } |
| 88 |
| 89 #sliderContainer { |
| 90 position: relative; |
| 91 width: calc(100% - 32px); |
| 92 height: 32px; |
| 93 } |
| 94 |
| 95 #sliderContainer:focus { |
| 96 outline: 0; |
| 97 } |
| 98 |
| 99 #sliderContainer.editable { |
| 100 float: left; |
| 101 width: calc(100% - 72px); |
| 102 margin: 12px 0; |
| 103 } |
| 104 |
| 105 .bar-container { |
| 106 position: absolute; |
| 107 top: 0; |
| 108 left: 16px; |
| 109 height: 100%; |
| 110 width: 100%; |
| 111 overflow: hidden; |
| 112 } |
| 113 |
| 114 .ring > .bar-container { |
| 115 left: 20px; |
| 116 width: calc(100% - 4px); |
| 117 transition: left 0.18s ease, width 0.18s ease; |
| 118 } |
| 119 |
| 120 .ring.expand:not(.pin) > .bar-container { |
| 121 left: 30px; |
| 122 width: calc(100% - 14px); |
| 123 } |
| 124 |
| 125 .ring.expand.dragging > .bar-container { |
| 126 transition: none; |
| 127 } |
| 128 |
| 129 #sliderBar { |
| 130 position: absolute; |
| 131 top: 15px; |
| 132 left: 0; |
| 133 width: 100%; |
| 134 padding: 8px 0; |
| 135 margin: -8px 0; |
| 136 background-color: var(--paper-slider-bar-color, transparent); |
| 137 --paper-progress-height: var(--paper-slider-height, 2px); |
| 138 } |
| 139 |
| 140 .ring #sliderBar { |
| 141 left: -4px; |
| 142 width: calc(100% + 4px); |
| 143 } |
| 144 |
| 145 .ring.expand:not(.pin) #sliderBar { |
| 146 left: -14px; |
| 147 width: calc(100% + 14px); |
| 148 } |
| 149 |
| 150 .slider-markers { |
| 151 position: absolute; |
| 152 top: 15px; |
| 153 left: 15px; |
| 154 height: 2px; |
| 155 width: calc(100% + 2px); |
| 156 box-sizing: border-box; |
| 157 pointer-events: none; |
| 158 } |
| 159 |
| 160 .slider-markers::after, |
| 161 .slider-marker::after { |
| 162 content: ""; |
| 163 display: block; |
| 164 width: 2px; |
| 165 height: 2px; |
| 166 border-radius: 50%; |
| 167 background-color: black; |
| 168 } |
| 169 |
| 170 #sliderKnob { |
| 171 @apply(--layout-center-justified); |
| 172 @apply(--layout-center); |
| 173 @apply(--layout-horizontal); |
| 174 |
| 175 position: absolute; |
| 176 left: 0; |
| 177 top: 0; |
| 178 width: 32px; |
| 179 height: 32px; |
| 180 } |
| 181 |
| 182 .transiting > #sliderKnob { |
| 183 transition: left 0.08s ease; |
| 184 } |
| 185 |
| 186 #sliderKnob:focus { |
| 187 outline: none; |
| 188 } |
| 189 |
| 190 #sliderKnob.dragging { |
| 191 transition: none; |
| 192 } |
| 193 |
| 194 .snaps > #sliderKnob.dragging { |
| 195 transition: -webkit-transform 0.08s ease; |
| 196 transition: transform 0.08s ease; |
| 197 } |
| 198 |
| 199 #sliderKnobInner { |
| 200 width: 12px; |
| 201 height: 12px; |
| 202 border-radius: 50%; |
| 203 background-color: var(--paper-slider-knob-color, --google-blue-700); |
| 204 |
| 205 -moz-box-sizing: border-box; |
| 206 box-sizing: border-box; |
| 207 |
| 208 transition-property: height, width, background-color, border; |
| 209 transition-duration: 0.1s; |
| 210 transition-timing-function: ease; |
| 211 } |
| 212 |
| 213 .expand:not(.pin) > #sliderKnob > #sliderKnobInner { |
| 214 width: 100%; |
| 215 height: 100%; |
| 216 |
| 217 -webkit-transform: translateZ(0); |
| 218 transform: translateZ(0); |
| 219 } |
| 220 |
| 221 .ring > #sliderKnob > #sliderKnobInner { |
| 222 background-color: var(--paper-slider-knob-start-color, transparent); |
| 223 border: 2px solid var(--paper-slider-knob-start-border-color, #c8c8c8); |
| 224 } |
| 225 |
| 226 #sliderKnobInner::before { |
| 227 background-color: var(--paper-slider-pin-color, --google-blue-700); |
| 228 } |
| 229 |
| 230 .pin > #sliderKnob > #sliderKnobInner::before { |
| 231 content: ""; |
| 232 position: absolute; |
| 233 top: 0; |
| 234 left: 0; |
| 235 width: 26px; |
| 236 height: 26px; |
| 237 margin-left: 3px; |
| 238 border-radius: 50% 50% 50% 0; |
| 239 |
| 240 -webkit-transform: rotate(-45deg) scale(0) translate(0); |
| 241 transform: rotate(-45deg) scale(0) translate(0); |
| 242 } |
| 243 |
| 244 #sliderKnobInner::before, |
| 245 #sliderKnobInner::after { |
| 246 transition: -webkit-transform .2s ease, background-color .18s ease; |
| 247 transition: transform .2s ease, background-color .18s ease; |
| 248 } |
| 249 |
| 250 .pin.ring > #sliderKnob > #sliderKnobInner::before { |
| 251 background-color: var(--paper-slider-pin-start-color, #c8c8c8); |
| 252 } |
| 253 |
| 254 .pin.expand > #sliderKnob > #sliderKnobInner::before { |
| 255 -webkit-transform: rotate(-45deg) scale(1) translate(17px, -17px); |
| 256 transform: rotate(-45deg) scale(1) translate(17px, -17px); |
| 257 } |
| 258 |
| 259 .pin > #sliderKnob > #sliderKnobInner::after { |
| 260 content: attr(value); |
| 261 position: absolute; |
| 262 top: 0; |
| 263 left: 0; |
| 264 width: 32px; |
| 265 height: 26px; |
| 266 text-align: center; |
| 267 color: var(--paper-slider-font-color, #fff); |
| 268 font-size: 10px; |
| 269 |
| 270 -webkit-transform: scale(0) translate(0); |
| 271 transform: scale(0) translate(0); |
| 272 } |
| 273 |
| 274 .pin.expand > #sliderKnob > #sliderKnobInner::after { |
| 275 -webkit-transform: scale(1) translate(0, -17px); |
| 276 transform: scale(1) translate(0, -17px); |
| 277 } |
| 278 |
| 279 /* paper-input */ |
| 280 .slider-input { |
| 281 width: 50px; |
| 282 float: right; |
| 283 overflow: hidden; |
| 284 --paper-input-container-input: { |
| 285 text-align: center; |
| 286 }; |
| 287 } |
| 288 |
| 289 /* disabled state */ |
| 290 #sliderContainer.disabled { |
| 291 pointer-events: none; |
| 292 } |
| 293 |
| 294 .disabled > #sliderKnob > #sliderKnobInner { |
| 295 width: 8px; |
| 296 height: 8px; |
| 297 background-color: var(--paper-slider-disabled-knob-color, --google-grey-
500); |
| 298 } |
| 299 |
| 300 .disabled.ring > #sliderKnob > #sliderKnobInner { |
| 301 background-color: transparent; |
| 302 } |
| 303 |
| 304 paper-ripple { |
| 305 color: var(--paper-slider-knob-color, --google-blue-700); |
| 306 } |
| 307 |
| 308 </style> |
68 <div id="sliderContainer" | 309 <div id="sliderContainer" |
69 class$="[[_getClassNames(disabled, pin, snaps, immediateValue, min, expand
, dragging, transiting, editable)]]"> | 310 class$="[[_getClassNames(disabled, pin, snaps, immediateValue, min, expand
, dragging, transiting, editable)]]"> |
70 | 311 |
71 <div class="bar-container"> | 312 <div class="bar-container"> |
72 <paper-progress | 313 <paper-progress |
73 disabled$="[[disabled]]" | 314 disabled$="[[disabled]]" |
74 id="sliderBar" | 315 id="sliderBar" |
75 aria-hidden="true" | 316 aria-hidden="true" |
76 min="[[min]]" | 317 min="[[min]]" |
77 max="[[max]]" | 318 max="[[max]]" |
(...skipping 13 matching lines...) Expand all Loading... |
91 </template> | 332 </template> |
92 </div> | 333 </div> |
93 </template> | 334 </template> |
94 | 335 |
95 <div id="sliderKnob" | 336 <div id="sliderKnob" |
96 class="center-justified center horizontal layout" | 337 class="center-justified center horizontal layout" |
97 on-down="_knobdown" | 338 on-down="_knobdown" |
98 on-up="_resetKnob" | 339 on-up="_resetKnob" |
99 on-track="_onTrack" | 340 on-track="_onTrack" |
100 on-transitionend="_knobTransitionEnd"> | 341 on-transitionend="_knobTransitionEnd"> |
101 <paper-ripple | |
102 center | |
103 id="ink" | |
104 class="circle" | |
105 hidden$="[[!receivedFocusFromKeyboard]]"> | |
106 </paper-ripple> | |
107 <div id="sliderKnobInner" value$="[[immediateValue]]"></div> | 342 <div id="sliderKnobInner" value$="[[immediateValue]]"></div> |
108 </div> | 343 </div> |
109 </div> | 344 </div> |
110 | |
111 <template is="dom-if" if="[[editable]]"> | 345 <template is="dom-if" if="[[editable]]"> |
112 <paper-input | 346 <paper-input |
113 id="input" | 347 id="input" |
| 348 type="number" |
| 349 step="[[step]]" |
| 350 min="[[min]]" |
| 351 max="[[max]]" |
114 class="slider-input" | 352 class="slider-input" |
115 disabled$="[[disabled]]" | 353 disabled$="[[disabled]]" |
116 on-change="_inputChange" | 354 value="[[immediateValue]]" |
117 value="[[_fixForInput(immediateValue)]]" | 355 on-change="_changeValue" |
118 > | 356 on-keydown="_inputKeyDown" |
| 357 no-label-float> |
119 </paper-input> | 358 </paper-input> |
120 </template> | 359 </template> |
121 </template> | 360 </template> |
122 | |
123 </dom-module> | 361 </dom-module> |
124 | 362 |
125 <script> | 363 <script> |
126 | 364 |
127 Polymer({ | 365 Polymer({ |
128 is: 'paper-slider', | 366 is: 'paper-slider', |
129 | 367 |
130 behaviors: [ | 368 behaviors: [ |
131 Polymer.IronFormElementBehavior, | 369 Polymer.IronFormElementBehavior, |
132 Polymer.PaperInkyFocusBehavior, | 370 Polymer.PaperInkyFocusBehavior, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 459 |
222 markers: { | 460 markers: { |
223 type: Array, | 461 type: Array, |
224 readOnly: true, | 462 readOnly: true, |
225 value: [] | 463 value: [] |
226 }, | 464 }, |
227 }, | 465 }, |
228 | 466 |
229 observers: [ | 467 observers: [ |
230 '_updateKnob(value, min, max, snaps, step)', | 468 '_updateKnob(value, min, max, snaps, step)', |
231 '_minChanged(min)', | |
232 '_maxChanged(max)', | |
233 '_valueChanged(value)', | 469 '_valueChanged(value)', |
234 '_immediateValueChanged(immediateValue)' | 470 '_immediateValueChanged(immediateValue)' |
235 ], | 471 ], |
236 | 472 |
237 hostAttributes: { | 473 hostAttributes: { |
238 role: 'slider', | 474 role: 'slider', |
239 tabindex: 0 | 475 tabindex: 0 |
240 }, | 476 }, |
241 | 477 |
242 keyBindings: { | 478 keyBindings: { |
243 'left down pagedown home': '_decrementKey', | 479 'left down pagedown home': '_decrementKey', |
244 'right up pageup end': '_incrementKey' | 480 'right up pageup end': '_incrementKey' |
245 }, | 481 }, |
246 | 482 |
247 ready: function() { | 483 ready: function() { |
248 // issue polymer/polymer#1305 | 484 // issue polymer/polymer#1305 |
249 | |
250 this.async(function() { | 485 this.async(function() { |
251 this._updateKnob(this.value); | 486 this._updateKnob(this.value); |
252 }, 1); | 487 }, 1); |
253 }, | 488 }, |
254 | 489 |
255 /** | 490 /** |
256 * Increases value by `step` but not above `max`. | 491 * Increases value by `step` but not above `max`. |
257 * @method increment | 492 * @method increment |
258 */ | 493 */ |
259 increment: function() { | 494 increment: function() { |
260 this.value = this._clampValue(this.value + this.step); | 495 this.value = this._clampValue(this.value + this.step); |
261 }, | 496 }, |
262 | 497 |
263 /** | 498 /** |
264 * Decreases value by `step` but not below `min`. | 499 * Decreases value by `step` but not below `min`. |
265 * @method decrement | 500 * @method decrement |
266 */ | 501 */ |
267 decrement: function() { | 502 decrement: function() { |
268 this.value = this._clampValue(this.value - this.step); | 503 this.value = this._clampValue(this.value - this.step); |
269 }, | 504 }, |
270 | 505 |
271 _updateKnob: function(value) { | 506 _updateKnob: function(value, min, max, snaps, step) { |
| 507 this.setAttribute('aria-valuemin', min); |
| 508 this.setAttribute('aria-valuemax', max); |
| 509 this.setAttribute('aria-valuenow', value); |
| 510 |
272 this._positionKnob(this._calcRatio(value)); | 511 this._positionKnob(this._calcRatio(value)); |
273 }, | 512 }, |
274 | 513 |
275 _minChanged: function() { | |
276 this.setAttribute('aria-valuemin', this.min); | |
277 }, | |
278 | |
279 _maxChanged: function() { | |
280 this.setAttribute('aria-valuemax', this.max); | |
281 }, | |
282 | |
283 _valueChanged: function() { | 514 _valueChanged: function() { |
284 this.setAttribute('aria-valuenow', this.value); | |
285 this.fire('value-change'); | 515 this.fire('value-change'); |
286 }, | 516 }, |
287 | 517 |
288 _immediateValueChanged: function() { | 518 _immediateValueChanged: function() { |
289 if (this.dragging) { | 519 if (this.dragging) { |
290 this.fire('immediate-value-change'); | 520 this.fire('immediate-value-change'); |
291 } else { | 521 } else { |
292 this.value = this.immediateValue; | 522 this.value = this.immediateValue; |
293 } | 523 } |
294 }, | 524 }, |
295 | 525 |
296 _secondaryProgressChanged: function() { | 526 _secondaryProgressChanged: function() { |
297 this.secondaryProgress = this._clampValue(this.secondaryProgress); | 527 this.secondaryProgress = this._clampValue(this.secondaryProgress); |
298 }, | 528 }, |
299 | 529 |
300 _fixForInput: function(immediateValue) { | |
301 // paper-input/issues/114 | |
302 return this.immediateValue.toString(); | |
303 }, | |
304 | |
305 _expandKnob: function() { | 530 _expandKnob: function() { |
306 this._setExpand(true); | 531 this._setExpand(true); |
307 }, | 532 }, |
308 | 533 |
309 _resetKnob: function() { | 534 _resetKnob: function() { |
310 this.cancelDebouncer('expandKnob'); | 535 this.cancelDebouncer('expandKnob'); |
311 this._setExpand(false); | 536 this._setExpand(false); |
312 }, | 537 }, |
313 | 538 |
314 _positionKnob: function(ratio) { | 539 _positionKnob: function(ratio) { |
315 this._setImmediateValue(this._calcStep(this._calcKnobPosition(ratio))); | 540 this._setImmediateValue(this._calcStep(this._calcKnobPosition(ratio))); |
316 this._setRatio(this._calcRatio(this.immediateValue)); | 541 this._setRatio(this._calcRatio(this.immediateValue)); |
317 | 542 |
318 this.$.sliderKnob.style.left = (this.ratio * 100) + '%'; | 543 this.$.sliderKnob.style.left = (this.ratio * 100) + '%'; |
319 }, | 544 }, |
320 | 545 |
321 _inputChange: function() { | |
322 this.value = this.$$('#input').value; | |
323 this.fire('change'); | |
324 }, | |
325 | |
326 _calcKnobPosition: function(ratio) { | 546 _calcKnobPosition: function(ratio) { |
327 return (this.max - this.min) * ratio + this.min; | 547 return (this.max - this.min) * ratio + this.min; |
328 }, | 548 }, |
329 | 549 |
330 _onTrack: function(event) { | 550 _onTrack: function(event) { |
331 event.stopPropagation(); | 551 event.stopPropagation(); |
332 switch (event.detail.state) { | 552 switch (event.detail.state) { |
333 case 'start': | 553 case 'start': |
334 this._trackStart(event); | 554 this._trackStart(event); |
335 break; | 555 break; |
336 case 'track': | 556 case 'track': |
337 this._trackX(event); | 557 this._trackX(event); |
338 break; | 558 break; |
339 case 'end': | 559 case 'end': |
340 this._trackEnd(); | 560 this._trackEnd(); |
341 break; | 561 break; |
342 } | 562 } |
343 }, | 563 }, |
344 | 564 |
345 _trackStart: function(event) { | 565 _trackStart: function(event) { |
346 this._w = this.$.sliderBar.offsetWidth; | 566 this._w = this.$.sliderBar.offsetWidth; |
347 this._x = this.ratio * this._w; | 567 this._x = this.ratio * this._w; |
348 this._startx = this._x || 0; | 568 this._startx = this._x || 0; |
349 this._minx = - this._startx; | 569 this._minx = - this._startx; |
350 this._maxx = this._w - this._startx; | 570 this._maxx = this._w - this._startx; |
351 this.$.sliderKnob.classList.add('dragging'); | 571 this.$.sliderKnob.classList.add('dragging'); |
352 | |
353 this._setDragging(true); | 572 this._setDragging(true); |
354 }, | 573 }, |
355 | 574 |
356 _trackX: function(e) { | 575 _trackX: function(e) { |
357 if (!this.dragging) { | 576 if (!this.dragging) { |
358 this._trackStart(e); | 577 this._trackStart(e); |
359 } | 578 } |
360 | 579 |
361 var dx = Math.min(this._maxx, Math.max(this._minx, e.detail.dx)); | 580 var dx = Math.min(this._maxx, Math.max(this._minx, e.detail.dx)); |
362 this._x = this._startx + dx; | 581 this._x = this._startx + dx; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 snaps: this.snaps, | 668 snaps: this.snaps, |
450 ring: this.immediateValue <= this.min, | 669 ring: this.immediateValue <= this.min, |
451 expand: this.expand, | 670 expand: this.expand, |
452 dragging: this.dragging, | 671 dragging: this.dragging, |
453 transiting: this.transiting, | 672 transiting: this.transiting, |
454 editable: this.editable | 673 editable: this.editable |
455 }); | 674 }); |
456 }, | 675 }, |
457 | 676 |
458 _incrementKey: function(event) { | 677 _incrementKey: function(event) { |
459 if (event.detail.key === 'end') { | 678 if (!this.disabled) { |
460 this.value = this.max; | 679 if (event.detail.key === 'end') { |
461 } else { | 680 this.value = this.max; |
462 this.increment(); | 681 } else { |
| 682 this.increment(); |
| 683 } |
| 684 this.fire('change'); |
463 } | 685 } |
| 686 }, |
| 687 |
| 688 _decrementKey: function(event) { |
| 689 if (!this.disabled) { |
| 690 if (event.detail.key === 'home') { |
| 691 this.value = this.min; |
| 692 } else { |
| 693 this.decrement(); |
| 694 } |
| 695 this.fire('change'); |
| 696 } |
| 697 }, |
| 698 |
| 699 _changeValue: function(event) { |
| 700 this.value = event.target.value; |
464 this.fire('change'); | 701 this.fire('change'); |
465 }, | 702 }, |
466 | 703 |
467 _decrementKey: function(event) { | 704 _inputKeyDown: function(event) { |
468 if (event.detail.key === 'home') { | 705 event.stopPropagation(); |
469 this.value = this.min; | 706 }, |
470 } else { | 707 |
471 this.decrement(); | 708 // create the element ripple inside the `sliderKnob` |
| 709 _createRipple: function() { |
| 710 this._rippleContainer = this.$.sliderKnob; |
| 711 return Polymer.PaperInkyFocusBehaviorImpl._createRipple.call(this); |
| 712 }, |
| 713 |
| 714 // Hide the ripple when user is not interacting with keyboard. |
| 715 // This behavior is different from other ripple-y controls, but is |
| 716 // according to spec: https://www.google.com/design/spec/components/sliders.
html |
| 717 _focusedChanged: function(receivedFocusFromKeyboard) { |
| 718 if (receivedFocusFromKeyboard) { |
| 719 this.ensureRipple(); |
472 } | 720 } |
473 this.fire('change'); | 721 if (this.hasRipple()) { |
| 722 // note, ripple must be un-hidden prior to setting `holdDown` |
| 723 if (receivedFocusFromKeyboard) { |
| 724 this._ripple.removeAttribute('hidden'); |
| 725 } else { |
| 726 this._ripple.setAttribute('hidden', ''); |
| 727 } |
| 728 this._ripple.holdDown = receivedFocusFromKeyboard; |
| 729 } |
474 } | 730 } |
| 731 |
475 }); | 732 }); |
476 | 733 |
477 /** | 734 /** |
478 * Fired when the slider's value changes. | 735 * Fired when the slider's value changes. |
479 * | 736 * |
480 * @event value-change | 737 * @event value-change |
481 */ | 738 */ |
482 | 739 |
483 /** | 740 /** |
484 * Fired when the slider's immediateValue changes. | 741 * Fired when the slider's immediateValue changes. |
485 * | 742 * |
486 * @event immediate-value-change | 743 * @event immediate-value-change |
487 */ | 744 */ |
488 | 745 |
489 /** | 746 /** |
490 * Fired when the slider's value changes due to user interaction. | 747 * Fired when the slider's value changes due to user interaction. |
491 * | 748 * |
492 * Changes to the slider's value due to changes in an underlying | 749 * Changes to the slider's value due to changes in an underlying |
493 * bound variable will not trigger this event. | 750 * bound variable will not trigger this event. |
494 * | 751 * |
495 * @event change | 752 * @event change |
496 */ | 753 */ |
497 | 754 |
498 </script> | 755 </script> |
OLD | NEW |