|
10 | 10 |
|
11 | 11 | <link rel="import" href="../polymer/polymer.html">
|
12 | 12 | <link rel="import" href="../paper-styles/default-theme.html">
|
13 |
| -<link rel="import" href="../paper-behaviors/paper-ripple-behavior.html"> |
| 13 | +<link rel="import" href="../paper-ripple/paper-ripple.html"> |
14 | 14 |
|
15 | 15 | <!--
|
16 | 16 | Material design: [Checkbox](https://www.google.com/design/spec/components/selection-controls.html#selection-controls-checkbox)
|
|
193 | 193 | Polymer({
|
194 | 194 | is: 'paper-checkbox-light',
|
195 | 195 |
|
196 |
| - behaviors: [ |
197 |
| - Polymer.PaperRippleBehavior |
198 |
| - ], |
199 |
| - |
200 | 196 | hostAttributes: {
|
201 | 197 | role: 'checkbox',
|
202 | 198 | tabindex: 0
|
203 | 199 | },
|
204 | 200 |
|
| 201 | + /** |
| 202 | + * Focus events occuring less than this value (in milliseconds) after a |
| 203 | + * 'down' event are considered to be the result of a pointer. |
| 204 | + */ |
| 205 | + __POINTER_FOCUS_WINDOW: 30, |
| 206 | + |
205 | 207 | properties: {
|
206 | 208 | checked: {
|
207 | 209 | type: Boolean,
|
|
215 | 217 | reflectToAttribute: true,
|
216 | 218 | observer: '_disabledChanged'
|
217 | 219 | },
|
| 220 | + |
| 221 | + noink: { |
| 222 | + type: Boolean |
| 223 | + }, |
218 | 224 | },
|
219 | 225 |
|
220 | 226 | listeners: {
|
221 | 227 | 'tap': '_onTap',
|
222 | 228 | 'keypress': '_onKeypress',
|
223 |
| - 'down': '_rippleDown', |
224 |
| - 'up': '_rippleUp', |
225 |
| - 'focus': '_rippleDown', |
226 |
| - 'blur': '_rippleUp' |
| 229 | + 'down': '_onDown', |
| 230 | + 'up': '_onUp', |
| 231 | + 'focus': '_onFocus', |
| 232 | + 'blur': '_onBlur' |
| 233 | + }, |
| 234 | + |
| 235 | + created: function() { |
| 236 | + this._lastDown = 0; |
227 | 237 | },
|
228 | 238 |
|
229 | 239 | attached: function() {
|
230 |
| - this.setAttribute('aria-checked', !!this.checked); |
231 |
| - this.setAttribute('aria-disabled', !!this.disabled); |
| 240 | + Polymer.RenderStatus.afterNextRender(this, function() { |
| 241 | + this.setAttribute('aria-checked', !!this.checked); |
| 242 | + this.setAttribute('aria-disabled', !!this.disabled); |
| 243 | + }); |
| 244 | + }, |
| 245 | + |
| 246 | + _checkedChanged: function(checked) { |
| 247 | + this.setAttribute('aria-checked', this.checked); |
| 248 | + }, |
| 249 | + |
| 250 | + _disabledChanged: function(disabled) { |
| 251 | + this.setAttribute('aria-disabled', this.disabled); |
232 | 252 | },
|
233 | 253 |
|
234 | 254 | _updateInkSize: function() {
|
|
267 | 287 | }
|
268 | 288 | },
|
269 | 289 |
|
270 |
| - _createRipple: function() { |
271 |
| - var ripple = Polymer.PaperRippleBehavior._createRipple.call(this); |
272 |
| - ripple.center = true; |
273 |
| - ripple.classList.add('circle'); |
274 |
| - return ripple; |
| 290 | + _onDown: function() { |
| 291 | + this._lastDown = Date.now(); |
| 292 | + this._updateInkSize(); |
275 | 293 | },
|
276 | 294 |
|
277 |
| - _rippleDown: function() { |
278 |
| - this._updateInkSize(); |
279 |
| - this.getRipple().downAction(); |
| 295 | + _onUp: function() { |
| 296 | + this._getRipple().holdDown = false; |
280 | 297 | },
|
281 | 298 |
|
282 |
| - _rippleUp: function() { |
| 299 | + _onFocus: function() { |
283 | 300 | this._updateInkSize();
|
284 |
| - this.getRipple().upAction(); |
| 301 | + var ripple = this._getRipple(); |
| 302 | + if ((Date.now() - this._lastDown) > this.__POINTER_FOCUS_WINDOW) { |
| 303 | + ripple.holdDown = true; |
| 304 | + this._lastDown = 0; |
| 305 | + ripple.downAction(); |
| 306 | + } |
285 | 307 | },
|
286 | 308 |
|
287 |
| - _checkedChanged: function(checked) { |
288 |
| - this.setAttribute('aria-checked', this.checked); |
| 309 | + _onBlur: function() { |
| 310 | + var ripple = this._getRipple() |
| 311 | + ripple.holdDown = false; |
| 312 | + ripple.upAction(); |
289 | 313 | },
|
290 | 314 |
|
291 |
| - _disabledChanged: function(disabled) { |
292 |
| - this.setAttribute('aria-disabled', this.disabled); |
| 315 | + _getRipple: function() { |
| 316 | + if (!this._ripple) { |
| 317 | + var ripple = document.createElement('paper-ripple'); |
| 318 | + ripple.center = true; |
| 319 | + ripple.classList.add('circle'); |
| 320 | + Polymer.dom(this.root).appendChild(ripple); |
| 321 | + this._ripple = ripple; |
| 322 | + } |
| 323 | + return this._ripple; |
293 | 324 | },
|
294 | 325 | });
|
295 | 326 | </script>
|
|
0 commit comments