|
168 | 168 | this.$.underlineContainer.style.top = height + 'px';
|
169 | 169 | },
|
170 | 170 |
|
| 171 | + prepareLabelTransform: function() { |
| 172 | + var toRect = this.$.floatedLabelSpan.getBoundingClientRect(); |
| 173 | + var fromRect = this.$.labelSpan.getBoundingClientRect(); |
| 174 | + if (toRect.width !== 0) { |
| 175 | + this.$.label.cachedTransform = 'scale(' + (toRect.width / fromRect.width) + ') ' + |
| 176 | + 'translateY(' + (toRect.bottom - fromRect.bottom) + 'px)'; |
| 177 | + } |
| 178 | + }, |
| 179 | + |
171 | 180 | rowsChanged: function() {
|
172 | 181 | if (this.multiline && !isNaN(parseInt(this.rows))) {
|
173 | 182 | this.$.minInputHeight.innerHTML = '';
|
|
212 | 221 |
|
213 | 222 | labelChanged: function() {
|
214 | 223 | if (this.floatingLabel && this.$.floatedLabel && this.$.label) {
|
215 |
| - var toRect = this.$.floatedLabelSpan.getBoundingClientRect(); |
216 |
| - var fromRect = this.$.labelSpan.getBoundingClientRect(); |
217 |
| - this.$.label.cachedTransform = 'scale(' + (toRect.width / fromRect.width) + ') ' + |
218 |
| - 'translateY(' + (toRect.bottom - fromRect.bottom) + 'px)' |
| 224 | + // If the element is created programmatically, labelChanged is called before |
| 225 | + // binding. Run the measuring code in async so the DOM is ready. |
| 226 | + this.async(function() { |
| 227 | + this.prepareLabelTransform(); |
| 228 | + }); |
219 | 229 | }
|
220 | 230 | },
|
221 | 231 |
|
|
330 | 340 | if (this.floatingLabel) {
|
331 | 341 | this.$.label.classList.add('focusedColor');
|
332 | 342 | this.$.label.classList.add('animating');
|
| 343 | + if (!this.$.label.cachedTransform) { |
| 344 | + this.prepareLabelTransform(); |
| 345 | + } |
333 | 346 | this.$.label.style.webkitTransform = this.$.label.cachedTransform;
|
334 | 347 | this.$.label.style.transform = this.$.label.cachedTransform;
|
335 | 348 | }
|
|
0 commit comments