Skip to content

Commit 66d563a

Browse files
committed
autofloat label for special types
1 parent b804029 commit 66d563a

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

paper-input-behavior.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,20 @@
394394
return this.inputElement;
395395
},
396396

397+
registered: function() {
398+
// These types have some default placeholder text; overlapping
399+
// the label on top of it looks terrible. Auto-float the label in this case.
400+
this._typesThatHaveText = ["date", "datetime", "datetime-local", "month",
401+
"time", "week", "file"];
402+
},
403+
397404
attached: function() {
398405
this._updateAriaLabelledBy();
406+
407+
if (this.inputElement &&
408+
this._typesThatHaveText.indexOf(this.inputElement.type) !== -1) {
409+
this.alwaysFloatLabel = true;
410+
}
399411
},
400412

401413
_appendStringWithSpace: function(str, more) {

paper-input.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
</paper-input>
4040
4141
A `paper-input` can use the native `type=search` or `type=file` features.
42-
However, since we can't control the native styling of the input, in these cases
43-
it's recommended to use a placeholder text, or `always-float-label`,
44-
as to not overlap the native UI (search icon, file button, etc.).
42+
However, since we can't control the native styling of the input (search icon,
43+
file button, date placeholder, etc.), in these cases the label will be
44+
automatically floated. The `placeholder` attribute can still be used for
45+
additional informational text.
4546
4647
<paper-input label="search!" type="search"
4748
placeholder="search for cats" autosave="test" results="5">

test/paper-input.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
</template>
7171
</test-fixture>
7272

73-
7473
<test-fixture id="required-char-counter">
7574
<template>
7675
<paper-input auto-validate char-counter required error-message="error"></paper-input>
@@ -95,6 +94,12 @@
9594
</template>
9695
</test-fixture>
9796

97+
<test-fixture id="date">
98+
<template>
99+
<paper-input label="foo" type="date"></paper-input>
100+
</template>
101+
</test-fixture>
102+
98103
<letters-only></letters-only>
99104

100105
<test-fixture id="validator">
@@ -121,6 +126,18 @@
121126
assert.ok(floatingLabel);
122127
});
123128

129+
test('special types autofloat the label', function() {
130+
var input = fixture('date');
131+
// Browsers that don't support special <input> types like `date` fallback
132+
// to `text`, so make sure to only test if type is still preserved after
133+
// the element is attached.
134+
if (input.inputElement.type === "date") {
135+
assert.equal(input.alwaysFloatLabel, true);
136+
var floatingLabel = Polymer.dom(Polymer.dom(input.root).querySelector('paper-input-container').root).querySelector('.label-is-floating');
137+
assert.ok(floatingLabel);
138+
}
139+
});
140+
124141
test('always-float-label attribute works without placeholder', function() {
125142
var input = fixture('always-float-label');
126143
var container = Polymer.dom(input.root).querySelector('paper-input-container');

0 commit comments

Comments
 (0)