Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: chrome/browser/resources/settings/controls/controlled_radio_button.js

Issue 2815593002: MD Settings: circumvent problems with shadow DOM and aria radio* roles (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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: [PrefControlBehavior],
9 9
10 properties: { 10 properties: {
11 label: String, 11 label: {
12 type: String,
13 observer: 'labelChanged_',
14 },
12 15
13 name: { 16 name: {
14 type: String, 17 type: String,
15 notify: true, 18 notify: true,
16 }, 19 },
17 20
18 /** @private */ 21 /** @private */
19 controlled_: { 22 controlled_: {
20 type: Boolean, 23 type: Boolean,
21 computed: 'computeControlled_(pref.*)', 24 computed: 'computeControlled_(pref.*)',
22 reflectToAttribute: true, 25 reflectToAttribute: true,
23 }, 26 },
24 }, 27 },
25 28
29 hostAttributes: {
30 // NOTE(dbeam): this should not be necessary but currently radiogroup and
31 // radio roles don't work across shadow DOM boundaries.
32 role: 'radio',
33 },
34
26 listeners: { 35 listeners: {
27 'focus': 'onFocus_', 36 'focus': 'onFocus_',
28 }, 37 },
29 38
30 /** 39 /**
31 * @return {boolean} Whether the button is disabled. 40 * @return {boolean} Whether the button is disabled.
32 * @private 41 * @private
33 */ 42 */
34 computeControlled_: function() { 43 computeControlled_: function() {
35 return this.pref.enforcement == chrome.settingsPrivate.Enforcement.ENFORCED; 44 return this.pref.enforcement == chrome.settingsPrivate.Enforcement.ENFORCED;
36 }, 45 },
37 46
47 /** @private */
48 labelChanged_: function() {
49 if (this.label)
50 this.setAttribute('aria-label', this.label);
51 else
52 this.removeAttribute('aria-label');
hcarmona 2017/04/11 17:47:25 There's only one case where label isn't set. http
53 },
54
38 /** 55 /**
39 * @param {boolean} controlled 56 * @param {boolean} controlled
40 * @param {string} name 57 * @param {string} name
41 * @return {boolean} 58 * @return {boolean}
42 * @private 59 * @private
43 */ 60 */
44 showIndicator_: function(controlled, name) { 61 showIndicator_: function(controlled, name) {
45 return controlled && 62 return controlled &&
46 name == Settings.PrefUtil.prefToString(assert(this.pref)); 63 name == Settings.PrefUtil.prefToString(assert(this.pref));
47 }, 64 },
48 65
49 /** 66 /**
50 * @param {!Event} e 67 * @param {!Event} e
51 * @private 68 * @private
52 */ 69 */
53 onIndicatorTap_: function(e) { 70 onIndicatorTap_: function(e) {
54 // Disallow <controlled-radio-button on-tap="..."> when controlled. 71 // Disallow <controlled-radio-button on-tap="..."> when controlled.
55 e.preventDefault(); 72 e.preventDefault();
56 e.stopPropagation(); 73 e.stopPropagation();
57 }, 74 },
58 75
59 /** Focuses the internal radio button when the row is selected. */ 76 /** Focuses the internal radio button when the row is selected. */
60 onFocus_: function() { 77 onFocus_: function() {
61 this.$.radioButton.focus(); 78 this.$.radioButton.focus();
62 }, 79 },
63 }); 80 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698