Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 9a05fab

Browse files
author
Yvonne Yip
committed
ensure the floating label animation is set up
1 parent 7e31331 commit 9a05fab

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

demo2.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ <h1>&lt;paper-input&gt;</h1>
8282
<paper-input floatingLabel label="Type only numbers... (floating)" validate="^[0-9]*$" error="Input is not a number!"></paper-input>
8383
</div>
8484
<div class="container">
85-
<paper-input multiline label="Type multiple lines here..."></paper-input>
85+
<paper-input multiline style="display:none;" label="Type multiple lines here..."></paper-input>
8686
</div>
8787
<div class="container">
8888
<paper-input multiline rows="3" label="This input is 3 rows high"></paper-input>

paper-input.html

+17-4
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@
168168
this.$.underlineContainer.style.top = height + 'px';
169169
},
170170

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+
171180
rowsChanged: function() {
172181
if (this.multiline && !isNaN(parseInt(this.rows))) {
173182
this.$.minInputHeight.innerHTML = '';
@@ -212,10 +221,11 @@
212221

213222
labelChanged: function() {
214223
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+
});
219229
}
220230
},
221231

@@ -330,6 +340,9 @@
330340
if (this.floatingLabel) {
331341
this.$.label.classList.add('focusedColor');
332342
this.$.label.classList.add('animating');
343+
if (!this.$.label.cachedTransform) {
344+
this.prepareLabelTransform();
345+
}
333346
this.$.label.style.webkitTransform = this.$.label.cachedTransform;
334347
this.$.label.style.transform = this.$.label.cachedTransform;
335348
}

0 commit comments

Comments
 (0)