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 }, |
| 19 |
| 20 label: { |
| 21 type: String, |
| 22 value: '', // Allows the hidden$= binding to run without being set. |
| 23 }, |
12 | 24 |
13 name: { | 25 name: { |
14 type: String, | 26 type: String, |
15 notify: true, | 27 notify: true, |
16 }, | 28 }, |
17 | 29 |
18 /** @private */ | 30 /** @private */ |
19 controlled_: { | 31 controlled_: { |
20 type: Boolean, | 32 type: Boolean, |
21 computed: 'computeControlled_(pref.*)', | 33 computed: 'computeControlled_(pref.*)', |
22 reflectToAttribute: true, | 34 reflectToAttribute: true, |
23 }, | 35 }, |
| 36 |
| 37 /** @private */ |
| 38 pressed_: Boolean, |
| 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'); |
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'].includes(e.type); |
62 }, | 107 }, |
63 }); | 108 }); |
OLD | NEW |