Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 14b7f6a

Browse files
committed
add support for noink; fix ripple behavior for pointer / keyboard focus
1 parent b9400af commit 14b7f6a

File tree

1 file changed

+56
-25
lines changed

1 file changed

+56
-25
lines changed

paper-checkbox-light.html

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<link rel="import" href="../polymer/polymer.html">
1212
<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">
1414

1515
<!--
1616
Material design: [Checkbox](https://www.google.com/design/spec/components/selection-controls.html#selection-controls-checkbox)
@@ -193,15 +193,17 @@
193193
Polymer({
194194
is: 'paper-checkbox-light',
195195

196-
behaviors: [
197-
Polymer.PaperRippleBehavior
198-
],
199-
200196
hostAttributes: {
201197
role: 'checkbox',
202198
tabindex: 0
203199
},
204200

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+
205207
properties: {
206208
checked: {
207209
type: Boolean,
@@ -215,20 +217,38 @@
215217
reflectToAttribute: true,
216218
observer: '_disabledChanged'
217219
},
220+
221+
noink: {
222+
type: Boolean
223+
},
218224
},
219225

220226
listeners: {
221227
'tap': '_onTap',
222228
'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;
227237
},
228238

229239
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);
232252
},
233253

234254
_updateInkSize: function() {
@@ -267,29 +287,40 @@
267287
}
268288
},
269289

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();
275293
},
276294

277-
_rippleDown: function() {
278-
this._updateInkSize();
279-
this.getRipple().downAction();
295+
_onUp: function() {
296+
this._getRipple().holdDown = false;
280297
},
281298

282-
_rippleUp: function() {
299+
_onFocus: function() {
283300
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+
}
285307
},
286308

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();
289313
},
290314

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;
293324
},
294325
});
295326
</script>

0 commit comments

Comments
 (0)