Skip to content

Commit f10c54b

Browse files
committed
Merge pull request #243 from PolymerElements/fix-prefilled-prefix-label
fix prefix even moar better
2 parents 4da53c8 + c19f8fc commit f10c54b

File tree

3 files changed

+60
-24
lines changed

3 files changed

+60
-24
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"homepage": "https://github.com/PolymerElements/paper-input",
2828
"ignore": [],
2929
"dependencies": {
30-
"polymer": "Polymer/polymer#^1.2.0",
30+
"polymer": "Polymer/polymer#^1.1.0",
3131
"iron-autogrow-textarea": "PolymerElements/iron-autogrow-textarea#^1.0.0",
3232
"iron-behaviors": "PolymerElements/iron-behaviors#^1.0.0",
3333
"iron-form-element-behavior": "PolymerElements/iron-form-element-behavior#^1.0.0",

paper-input-container.html

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -461,21 +461,6 @@
461461
} else {
462462
this._handleValue(this._inputElement);
463463
}
464-
465-
this._numberOfPrefixNodes = 0;
466-
this._prefixObserver = Polymer.dom(this.$.prefix).observeNodes(
467-
function(mutations) {
468-
// Keep track whether there's at least one prefix node, since it
469-
// affects laying out the floating label.
470-
this._numberOfPrefixNodes += mutations.addedNodes.length -
471-
mutations.removedNodes.length;
472-
}.bind(this));
473-
},
474-
475-
detached: function() {
476-
if (this._prefixObserver) {
477-
Polymer.dom(this.$.prefix).unobserveNodes(this._prefixObserver);
478-
}
479464
},
480465

481466
_onAddonAttached: function(event) {
@@ -567,16 +552,15 @@
567552

568553
if (alwaysFloatLabel || _inputHasContent) {
569554
cls += ' label-is-floating';
555+
// If the label is floating, ignore any offsets that may have been
556+
// applied from a prefix element.
557+
this.$.labelAndInputContainer.style.position = 'static';
558+
570559
if (invalid) {
571560
cls += ' is-invalid';
572561
} else if (focused) {
573562
cls += " label-is-highlighted";
574563
}
575-
// If a prefix element exists, the label has a horizontal offset
576-
// which needs to be undone when displayed as a floating label.
577-
if (this._numberOfPrefixNodes > 0) {
578-
this.$.labelAndInputContainer.style.position = 'static';
579-
}
580564
} else {
581565
// When the label is not floating, it should overlap the input element.
582566
if (label) {

test/paper-input-container.html

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@
4040
</template>
4141
</test-fixture>
4242

43+
<test-fixture id="prefix">
44+
<template>
45+
<paper-input-container>
46+
<div prefix>$</div>
47+
<label id="l">label</label>
48+
<input is="iron-input" id="i">
49+
</paper-input-container>
50+
</template>
51+
</test-fixture>
52+
53+
<test-fixture id="prefix-has-value">
54+
<template>
55+
<paper-input-container>
56+
<div prefix>$</div>
57+
<label id="l">label</label>
58+
<input is="iron-input" id="i" value="foo">
59+
</paper-input-container>
60+
</template>
61+
</test-fixture>
62+
4363
<test-fixture id="has-value">
4464
<template>
4565
<paper-input-container>
@@ -119,9 +139,12 @@
119139
assert.equal(getComputedStyle(container.querySelector('#l')).visibility, 'visible', 'label has visibility:visible');
120140
});
121141

122-
test('label is floated if value is initialized to not null', function() {
142+
test('label is floated if value is initialized to not null', function(done) {
123143
var container = fixture('has-value');
124-
assert.notEqual(getTransform(container.querySelector('#l')), 'none', 'label has transform');
144+
requestAnimationFrame(function() {
145+
assert.notEqual(getTransform(container.querySelector('#l')), 'none', 'label has transform');
146+
done();
147+
});
125148
});
126149

127150
test('label is invisible if no-label-float and value is initialized to not null', function() {
@@ -132,7 +155,36 @@
132155
test('label is floated if always-float-label is true', function() {
133156
var container = fixture('always-float');
134157
assert.notEqual(getTransform(container.querySelector('#l')), 'none', 'label has transform');
135-
})
158+
});
159+
160+
test('label is floated correctly with a prefix', function(done) {
161+
var container = fixture('prefix');
162+
var label = Polymer.dom(container).querySelector('#l');
163+
var input = Polymer.dom(container).querySelector('#i');
164+
165+
// Label is initially visible.
166+
assert.equal(getComputedStyle(label).visibility, 'visible', 'label has visibility:visible');
167+
168+
// After entering text, the label floats, and it is not indented.
169+
input.bindValue = 'foobar';
170+
requestAnimationFrame(function() {
171+
assert.notEqual(getTransform(label), 'none', 'label has transform');
172+
assert.equal(label.getBoundingClientRect().left, container.getBoundingClientRect().left);
173+
done();
174+
});
175+
});
176+
177+
test('label is floated correctly with a prefix and prefilled value', function(done) {
178+
var container = fixture('prefix-has-value');
179+
var label = Polymer.dom(container).querySelector('#l');
180+
181+
// The label floats, and it is not indented.
182+
requestAnimationFrame(function() {
183+
assert.notEqual(getTransform(label), 'none', 'label has transform');
184+
assert.equal(label.getBoundingClientRect().left, container.getBoundingClientRect().left);
185+
done();
186+
});
187+
});
136188

137189
});
138190

0 commit comments

Comments
 (0)