Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 Polymer({ | 5 Polymer({ |
| 6 is: 'controlled-radio-button', | 6 is: 'controlled-radio-button', |
| 7 | 7 |
| 8 behaviors: [PrefControlBehavior], | 8 behaviors: [ |
| 9 PrefControlBehavior, | |
| 10 Polymer.IronA11yKeysBehavior, | |
| 11 ], | |
| 9 | 12 |
| 10 properties: { | 13 properties: { |
| 11 label: String, | 14 checked: { |
| 15 type: Boolean, | |
| 16 reflectToAttribute: true, | |
| 17 observer: 'checkedChanged_', | |
| 18 notify: true, | |
| 19 }, | |
| 20 | |
| 21 label: { | |
| 22 type: String, | |
| 23 value: '', | |
|
hcarmona
2017/04/13 01:18:37
Nit: add a comment that this is needed to avoid a
Dan Beam
2017/04/13 01:22:58
Done.
| |
| 24 }, | |
| 12 | 25 |
| 13 name: { | 26 name: { |
| 14 type: String, | 27 type: String, |
| 15 notify: true, | 28 notify: true, |
| 16 }, | 29 }, |
| 17 | 30 |
| 18 /** @private */ | 31 /** @private */ |
| 19 controlled_: { | 32 controlled_: { |
| 20 type: Boolean, | 33 type: Boolean, |
| 21 computed: 'computeControlled_(pref.*)', | 34 computed: 'computeControlled_(pref.*)', |
| 22 reflectToAttribute: true, | 35 reflectToAttribute: true, |
| 23 }, | 36 }, |
| 37 | |
| 38 pressed_: Boolean, | |
|
dpapad
2017/04/13 00:35:09
@private
Dan Beam
2017/04/13 00:59:01
Done.
| |
| 39 }, | |
| 40 | |
| 41 hostAttributes: { | |
| 42 role: 'radio', | |
| 43 tabindex: 0, | |
| 24 }, | 44 }, |
| 25 | 45 |
| 26 listeners: { | 46 listeners: { |
| 27 'focus': 'onFocus_', | 47 'blur': 'updatePressed_', |
| 48 'down': 'updatePressed_', | |
| 49 'focus': 'updatePressed_', | |
| 50 'tap': 'onTap_', | |
| 51 'up': 'updatePressed_', | |
| 52 }, | |
| 53 | |
| 54 keyBindings: { | |
| 55 // This is mainly for screenreaders, which can perform actions on things | |
| 56 // that aren't focused (only focused things get synthetic click/tap events). | |
| 57 'enter:keyup': 'click', | |
| 58 'space:keyup': 'click', | |
| 59 }, | |
| 60 | |
| 61 /** @private */ | |
| 62 checkedChanged_: function() { | |
| 63 this.setAttribute('aria-checked', this.checked ? 'true' : 'false'); | |
|
dpapad
2017/04/13 00:35:09
Nit (optional): The following should be equivalent
Dan Beam
2017/04/13 00:59:01
so is !!this.checked, i just figured this is less
| |
| 28 }, | 64 }, |
| 29 | 65 |
| 30 /** | 66 /** |
| 31 * @return {boolean} Whether the button is disabled. | 67 * @return {boolean} Whether the button is disabled. |
| 32 * @private | 68 * @private |
| 33 */ | 69 */ |
| 34 computeControlled_: function() { | 70 computeControlled_: function() { |
| 35 return this.pref.enforcement == chrome.settingsPrivate.Enforcement.ENFORCED; | 71 return this.pref.enforcement == chrome.settingsPrivate.Enforcement.ENFORCED; |
| 36 }, | 72 }, |
| 37 | 73 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 49 /** | 85 /** |
| 50 * @param {!Event} e | 86 * @param {!Event} e |
| 51 * @private | 87 * @private |
| 52 */ | 88 */ |
| 53 onIndicatorTap_: function(e) { | 89 onIndicatorTap_: function(e) { |
| 54 // Disallow <controlled-radio-button on-tap="..."> when controlled. | 90 // Disallow <controlled-radio-button on-tap="..."> when controlled. |
| 55 e.preventDefault(); | 91 e.preventDefault(); |
| 56 e.stopPropagation(); | 92 e.stopPropagation(); |
| 57 }, | 93 }, |
| 58 | 94 |
| 59 /** Focuses the internal radio button when the row is selected. */ | 95 /** @private */ |
| 60 onFocus_: function() { | 96 onTap_: function() { |
| 61 this.$.radioButton.focus(); | 97 if (!this.controlled_) |
| 98 this.checked = true; | |
| 99 }, | |
| 100 | |
| 101 /** | |
| 102 * @param {!Event} e | |
| 103 * @private | |
| 104 */ | |
| 105 updatePressed_: function(e) { | |
| 106 this.pressed_ = ['down', 'focus'].indexOf(e.type) >= 0; | |
|
dpapad
2017/04/13 00:35:09
Nit (optional): Maybe use includes() instead of in
Dan Beam
2017/04/13 01:22:58
Done.
| |
| 62 }, | 107 }, |
| 63 }); | 108 }); |
| OLD | NEW |