This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
paper-input.html
145 lines (111 loc) · 3.69 KB
/
paper-input.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE
The complete set of authors may be found at http://polymer.github.io/AUTHORS
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS
-->
<!--
Material Design: <a href="http://www.google.com/design/spec/components/text-fields.html#text-fields-single-line-text-field">Single line text field</a>
`paper-input` is a single-line text field for user input. It is a convenience element composed of
a `paper-input-decorator` and a `input is="core-input"`.
Example:
<paper-input label="Your Name"></paper-input>
If you need more control over the `input` element, use `paper-input-decorator`.
Theming
-------
`paper-input` can be styled similarly to `paper-input-decorator`.
Form submission
---------------
Unlike inputs using `paper-input-decorator` directly, `paper-input` does not work out of
the box with the native `form` element. This is because the native `form` is not aware of
shadow DOM and does not treat `paper-input` as a form element.
Use `paper-input-decorator` directly, or see
<a href="https://github.com/garstasio/ajax-form">`ajax-form`</a> for a possible solution
to submitting a `paper-input`.
Validation
----------
Use `paper-input-decorator` if you would like to implement validation.
@group Paper Elements
@element paper-input
@homepage github.io
-->
<link href="../polymer/polymer.html" rel="import">
<link href="../core-input/core-input.html" rel="import">
<link href="paper-input-decorator.html" rel="import">
<polymer-element name="paper-input">
<template>
<style>
:host {
display: inline-block;
}
</style>
<paper-input-decorator id="decorator" label="{{label}}" floatingLabel="{{floatingLabel}}" value="{{value}}" disabled?="{{disabled}}">
<input is="core-input" id="input" value="{{value}}" committedValue="{{committedValue}}" on-change="{{changeAction}}" disabled?="{{disabled}}">
</paper-input-decorator>
</template>
<script>
Polymer('paper-input', {
publish: {
/**
* The label for this input. It normally appears as grey text inside
* the text input and disappears once the user enters text.
*
* @attribute label
* @type string
* @default ''
*/
label: '',
/**
* If true, the label will "float" above the text input once the
* user enters text instead of disappearing.
*
* @attribute floatingLabel
* @type boolean
* @default false
*/
floatingLabel: false,
/**
* Set to true to style the element as disabled.
*
* @attribute disabled
* @type boolean
* @default false
*/
disabled: {value: false, reflect: true},
/**
* The current value of the input.
*
* @attribute value
* @type String
* @default ''
*/
value: '',
/**
* The most recently committed value of the input.
*
* @attribute committedValue
* @type String
* @default ''
*/
committedValue: ''
},
/**
* Focuses the `input`.
*
* @method focus
*/
focus: function() {
this.$.input.focus();
},
valueChanged: function() {
this.$.decorator.updateLabelVisibility(this.value);
},
changeAction: function(e) {
// re-fire event that does not bubble across shadow roots
this.fire('change', null, this);
}
});
</script>
</polymer-element>