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

Side by Side Diff: lib/src/paper-radio-button/paper-radio-button.html

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 1 month 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
« no previous file with comments | « lib/src/paper-progress/paper-progress.html ('k') | lib/src/paper-radio-button/test/basic.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 @license
2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt 4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt
6 Code distributed by Google as part of the polymer project is also 7 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
8 --> 9 -->
9 10
10 <link rel="import" href="../polymer/polymer.html"> 11 <link rel="import" href="../polymer/polymer.html">
12 <link rel="import" href="../paper-behaviors/paper-checked-element-behavior.html" >
11 <link rel="import" href="../paper-ripple/paper-ripple.html"> 13 <link rel="import" href="../paper-ripple/paper-ripple.html">
12 <link rel="import" href="../paper-styles/default-theme.html"> 14 <link rel="import" href="../paper-styles/default-theme.html">
13 <link rel="import" href="../paper-behaviors/paper-inky-focus-behavior.html">
14 <link rel="import" href="../iron-checked-element-behavior/iron-checked-element-b ehavior.html">
15 15
16 <!-- 16 <!--
17 Material design: [Radio button](https://www.google.com/design/spec/components/se lection-controls.html#selection-controls-radio-button)
18
17 `paper-radio-button` is a button that can be either checked or unchecked. 19 `paper-radio-button` is a button that can be either checked or unchecked.
18 User can tap the radio button to check or uncheck it. 20 User can tap the radio button to check or uncheck it.
19 21
20 Use a `<paper-radio-group>` to group a set of radio buttons. When radio buttons 22 Use a `<paper-radio-group>` to group a set of radio buttons. When radio buttons
21 are inside a radio group, exactly one radio button in the group can be checked 23 are inside a radio group, exactly one radio button in the group can be checked
22 at any time. 24 at any time.
23 25
24 Example: 26 Example:
25 27
26 <paper-radio-button></paper-radio-button> 28 <paper-radio-button></paper-radio-button>
27 <paper-radio-button>Item label</paper-radio-button> 29 <paper-radio-button>Item label</paper-radio-button>
28 30
29 ### Styling 31 ### Styling
30 32
31 The following custom properties and mixins are available for styling: 33 The following custom properties and mixins are available for styling:
32 34
33 Custom property | Description | Default 35 Custom property | Description | Default
34 ----------------|-------------|---------- 36 ----------------|-------------|----------
35 `--paper-radio-button-unchecked-background-color` | Radio button background colo r when the input is not checked | `transparent` 37 `--paper-radio-button-unchecked-background-color` | Radio button background colo r when the input is not checked | `transparent`
36 `--paper-radio-button-unchecked-color` | Radio button color when the input is no t checked | `--primary-text-color` 38 `--paper-radio-button-unchecked-color` | Radio button color when the input is no t checked | `--primary-text-color`
37 `--paper-radio-button-unchecked-ink-color` | Selected/focus ripple color when th e input is not checked | `--primary-text-color` 39 `--paper-radio-button-unchecked-ink-color` | Selected/focus ripple color when th e input is not checked | `--primary-text-color`
38 `--paper-radio-button-checked-color` | Radio button color when the input is chec ked | `--default-primary-color` 40 `--paper-radio-button-checked-color` | Radio button color when the input is chec ked | `--default-primary-color`
39 `--paper-radio-button-checked-ink-color` | Selected/focus ripple color when the input is checked | `--default-primary-color` 41 `--paper-radio-button-checked-ink-color` | Selected/focus ripple color when the input is checked | `--default-primary-color`
40 `--paper-radio-button-label-color` | Label color | `--primary-text-color` 42 `--paper-radio-button-label-color` | Label color | `--primary-text-color`
43 `--paper-radio-button-label-spacing` | Spacing between the label and the button | `10px`
41 44
42 @group Paper Elements 45 @group Paper Elements
43 @element paper-radio-button 46 @element paper-radio-button
44 @hero hero.svg 47 @hero hero.svg
45 @demo demo/index.html 48 @demo demo/index.html
46 --> 49 -->
47 50
48 <dom-module id="paper-radio-button"> 51 <dom-module id="paper-radio-button">
49 <template> 52 <template strip-whitespace>
50 <style> 53 <style>
51 :host { 54 :host {
52 display: inline-block; 55 display: inline-block;
53 white-space: nowrap; 56 white-space: nowrap;
54 } 57 }
55 58
56 :host(:focus) { 59 :host(:focus) {
57 outline: none; 60 outline: none;
58 } 61 }
59 62
60 #radioContainer { 63 #radioContainer {
61 display: inline-block; 64 display: inline-block;
62 position: relative; 65 position: relative;
63 width: 16px; 66 width: 16px;
64 height: 16px; 67 height: 16px;
65 cursor: pointer; 68 cursor: pointer;
66 vertical-align: middle; 69 vertical-align: middle;
67 } 70 }
68 71
69 :host #ink { 72 #ink {
70 position: absolute; 73 position: absolute;
71 top: -16px; 74 top: -16px;
72 left: -16px; 75 left: -16px;
73 width: 48px; 76 width: 48px;
74 height: 48px; 77 height: 48px;
75 color: var(--paper-radio-button-unchecked-ink-color, --primary-text-colo r); 78 color: var(--paper-radio-button-unchecked-ink-color, --primary-text-colo r);
76 opacity: 0.6; 79 opacity: 0.6;
77 pointer-events: none; 80 pointer-events: none;
78 } 81 }
79 82
80 :host #ink[checked] { 83 :host-context([dir="rtl"]) #ink {
84 right: -15px;
85 left: auto;
86 }
87
88 #ink[checked] {
81 color: var(--paper-radio-button-checked-ink-color, --default-primary-col or); 89 color: var(--paper-radio-button-checked-ink-color, --default-primary-col or);
82 } 90 }
83 91
84 :host #offRadio { 92 #offRadio {
85 position: absolute; 93 position: absolute;
86 box-sizing: content-box; 94 box-sizing: content-box;
87 top: 0px; 95 top: 0px;
88 left: 0px; 96 left: 0px;
97 right: 0px;
89 width: 12px; 98 width: 12px;
90 height: 12px; 99 height: 12px;
91 border-radius: 50%; 100 border-radius: 50%;
92 border: solid 2px; 101 border: solid 2px;
93 background-color: var(--paper-radio-button-unchecked-background-color, t ransparent); 102 background-color: var(--paper-radio-button-unchecked-background-color, t ransparent);
94 border-color: var(--paper-radio-button-unchecked-color, --primary-text-c olor); 103 border-color: var(--paper-radio-button-unchecked-color, --primary-text-c olor);
95 transition: border-color 0.28s; 104 transition: border-color 0.28s;
96 } 105 }
97 106
98 :host #onRadio { 107 #onRadio {
99 position: absolute; 108 position: absolute;
100 box-sizing: content-box; 109 box-sizing: content-box;
101 top: 4px; 110 top: 4px;
102 left: 4px; 111 left: 4px;
112 right: 4px;
103 width: 8px; 113 width: 8px;
104 height: 8px; 114 height: 8px;
105 border-radius: 50%; 115 border-radius: 50%;
106 background-color: var(--paper-radio-button-checked-color, --default-prim ary-color); 116 background-color: var(--paper-radio-button-checked-color, --default-prim ary-color);
107 -webkit-transform: scale(0); 117 -webkit-transform: scale(0);
108 transform: scale(0); 118 transform: scale(0);
109 transition: -webkit-transform ease 0.28s; 119 transition: -webkit-transform ease 0.28s;
110 transition: transform ease 0.28s; 120 transition: transform ease 0.28s;
111 } 121 }
112 122
113 :host([checked]) #offRadio { 123 :host([checked]) #offRadio {
114 border-color: var(--paper-radio-button-checked-color, --default-primary- color); 124 border-color: var(--paper-radio-button-checked-color, --default-primary- color);
115 } 125 }
116 126
117 :host([checked]) #onRadio { 127 :host([checked]) #onRadio {
118 -webkit-transform: scale(1); 128 -webkit-transform: scale(1);
119 transform: scale(1); 129 transform: scale(1);
120 } 130 }
121 131
122 #radioLabel { 132 #radioLabel {
123 position: relative; 133 position: relative;
124 display: inline-block; 134 display: inline-block;
125 vertical-align: middle; 135 vertical-align: middle;
126 margin-left: 10px; 136 margin-left: var(--paper-radio-button-label-spacing, 10px);
127 white-space: normal; 137 white-space: normal;
128 pointer-events: none; 138 pointer-events: none;
129 color: var(--paper-radio-button-label-color, --primary-text-color); 139 color: var(--paper-radio-button-label-color, --primary-text-color);
130 } 140 }
131 141
142 :host-context([dir="rtl"]) #radioLabel {
143 margin-left: 0px;
144 margin-right: var(--paper-radio-button-label-spacing, 10px);
145 }
146
132 #radioLabel[hidden] { 147 #radioLabel[hidden] {
133 display: none; 148 display: none;
134 } 149 }
135 150
136 /* disabled state */ 151 /* disabled state */
137 :host([disabled]) { 152 :host([disabled]) {
138 pointer-events: none; 153 pointer-events: none;
139 } 154 }
140 155
141 :host([disabled]) #offRadio { 156 :host([disabled]) #offRadio {
142 border-color: var(--paper-radio-button-unchecked-color, --primary-text-c olor); 157 border-color: var(--paper-radio-button-unchecked-color, --primary-text-c olor);
143 opacity: 0.5; 158 opacity: 0.5;
144 } 159 }
145 160
146 :host([disabled][checked]) #onRadio { 161 :host([disabled][checked]) #onRadio {
147 background-color: var(--paper-radio-button-unchecked-color, --primary-te xt-color); 162 background-color: var(--paper-radio-button-unchecked-color, --primary-te xt-color);
148 opacity: 0.5; 163 opacity: 0.5;
149 } 164 }
150 165
151 :host([disabled]) #radioLabel { 166 :host([disabled]) #radioLabel {
152 /* slightly darker than the button, so that it's readable */ 167 /* slightly darker than the button, so that it's readable */
153 opacity: 0.65; 168 opacity: 0.65;
154 } 169 }
155 </style> 170 </style>
156 171
157 <div id="radioContainer"> 172 <div id="radioContainer">
158 <div id="offRadio"></div> 173 <div id="offRadio"></div>
159 <div id="onRadio"></div> 174 <div id="onRadio"></div>
160 <paper-ripple id="ink" class="circle" center checked$="[[checked]]"></pape r-ripple>
161 </div> 175 </div>
162 176
163 <div id="radioLabel"><content></content></div> 177 <div id="radioLabel"><content></content></div>
164
165 </template> 178 </template>
166 179
167 <script> 180 <script>
168 Polymer({ 181 Polymer({
169 is: 'paper-radio-button', 182 is: 'paper-radio-button',
170 183
171 behaviors: [ 184 behaviors: [
172 Polymer.PaperInkyFocusBehavior, 185 Polymer.PaperCheckedElementBehavior
173 Polymer.IronCheckedElementBehavior
174 ], 186 ],
175 187
176 hostAttributes: { 188 hostAttributes: {
177 role: 'radio', 189 role: 'radio',
178 'aria-checked': false, 190 'aria-checked': false,
179 tabindex: 0 191 tabindex: 0
180 }, 192 },
181 193
182 properties: { 194 properties: {
183 /** 195 /**
184 * Fired when the checked state changes due to user interaction. 196 * Fired when the checked state changes due to user interaction.
185 * 197 *
186 * @event change 198 * @event change
187 */ 199 */
188 200
189 /** 201 /**
190 * Fired when the checked state changes. 202 * Fired when the checked state changes.
191 * 203 *
192 * @event iron-change 204 * @event iron-change
193 */ 205 */
194 206
195 ariaActiveAttribute: { 207 ariaActiveAttribute: {
196 value: 'aria-checked' 208 type: String,
197 } 209 value: 'aria-checked'
198 },
199
200 attached: function() {
201 this._isReady = true;
202
203 // Don't stomp over a user-set aria-label.
204 if (!this.getAttribute('aria-label')) {
205 this.updateAriaLabel();
206 } 210 }
207 }, 211 },
208 212
209 /** 213 // create the element ripple inside the `radioContainer`
210 * Update the checkbox aria-label. This is a temporary workaround not 214 _createRipple: function() {
211 * being able to observe changes in <content> 215 this._rippleContainer = this.$.radioContainer;
212 * (see: https://github.com/Polymer/polymer/issues/1773) 216 return Polymer.PaperInkyFocusBehaviorImpl._createRipple.call(this);
213 *
214 * Call this if you manually change the contents of the checkbox
215 * and want the aria-label to match the new contents.
216 */
217 updateAriaLabel: function() {
218 this.setAttribute('aria-label', Polymer.dom(this).textContent.trim());
219 },
220
221 _buttonStateChanged: function() {
222 if (this.disabled) {
223 return;
224 }
225 if (this._isReady) {
226 this.checked = this.active;
227 }
228 } 217 }
229 }) 218 })
230 </script> 219 </script>
231
232 </dom-module> 220 </dom-module>
OLDNEW
« no previous file with comments | « lib/src/paper-progress/paper-progress.html ('k') | lib/src/paper-radio-button/test/basic.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698