-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaper-input-wrapper.html
More file actions
159 lines (131 loc) · 4.53 KB
/
paper-input-wrapper.html
File metadata and controls
159 lines (131 loc) · 4.53 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-input/paper-input.html">
<dom-module id="paper-input-wrapper">
<template id="style">
<style>
:host {
display: block;
@apply --paper-input-wrapper;
--paper-input-container-underline: {
display: none;
}
--paper-input-container-underline-focus: {
display: none;
}
}
:host.layout.horizontal .content-container {
@apply --layout-horizontal;
}
:host.layout.vertical .content-container {
@apply --layout-vertical;
}
:host.layout paper-input-container {
@apply --layout-flex-auto;
}
.placeholder {
color: var(--paper-input-placeholder-color, var(--secondary-text-color));
font-size: var(--paper-input-wrapper-placehoder-size, 13px);
}
paper-input-container {
--paper-input-prefix: {
max-width: 90px;
margin-right: 5px;
line-height: 15px;
font-size: 13px;
}
--paper-input-suffix: {
max-width: 90px;
margin-left: 5px;
font-size: 13px;
line-height: 15px;
}
}
::slotted(paper-input-matrix) {
margin-top: 20px;
}
</style>
</template>
<template id="content">
<template is="dom-if" if="[[placeholder]]">
<div slot="input" class="placeholder">
[[placeholder]]
</div>
</template>
<div slot="input" id$="[[_inputId]]" class="paper-input-input content-container">
<slot></slot>
</div>
</template>
<script>
(function() {
let subTemplate;
customElements.whenDefined('paper-input').then(() => {
const PaperInput = customElements.get('paper-input');
/**
* ## PaperInputWrapper
*
* `<paper-input-wrapper>` extends paper-input to be able to wrap form elements without labels
* (e.g. radio-group) and provide them with label/placeholder.
*
* @memberof PolymerEl
* @customElement
* @polymer
* @demo
**/
class PaperInputWrapper extends PaperInput {
static get is() { return 'paper-input-wrapper'; }
// Note(cg): this is a temp ugly hack as cannot override
// hostAttributes applied while constructing PaperInput Class.
_ensureAttributes() {
super._ensureAttributes();
this.removeAttribute('tabindex');
}
static get properties() {
return {
/**
* Set to true to always float the label. If you're using PaperInputBehavior
* to implement your own paper-input-like element, bind this to the
* `<paper-input-container>`'s `alwaysFloatLabel` property.
*/
alwaysFloatLabel: { type: Boolean, value: true },
};
}
static get template() {
if (!subTemplate) {
subTemplate = PaperInput.template.cloneNode(true);
const tplContent = Polymer.DomModule.import('paper-input-wrapper', 'template#content').content;
const tplStyle = Polymer.DomModule.import('paper-input-wrapper', 'template#style').content;
const anchor = subTemplate.content.querySelector('#container');
subTemplate.content.querySelector('style').parentNode.appendChild(tplStyle);
anchor.replaceChild(tplContent, anchor.querySelector('iron-input') || anchor.querySelector('input'));
}
return subTemplate;
}
// Note(cg): overriding this function is creating an error for element that do not have an `input` id.
_onIronInputReady() {
// Even though this is only used in the next line, save this for
// backwards compatibility, since the native input had this ID until 2.0.5.
if (!this.$.nativeInput) {
this.$.nativeInput = this.$$('input');
}
if (this.inputElement && this.$.nativeInput &&
this._typesThatHaveText.indexOf(this.$.nativeInput.type) !== -1) {
this.alwaysFloatLabel = true;
}
// Only validate when attached if the input already has a value.
if (!!this.inputElement.bindValue) {
this.$.container._handleValueAndAutoValidate(this.inputElement);
}
}
}
customElements.define(PaperInputWrapper.is, PaperInputWrapper);
if (!window.PolymerEl) {
window.PolymerEl = {};
}
/*
* @namespace MultiChart
*/
window.PolymerEl.PaperInputWrapper = PaperInputWrapper;
});
})();
</script>
</dom-module>